You are on page 1of 127

Home

Turbo C

u

uuuGef

rmwd u m
pOf

taMumif ; t&m

pmrsuf E S m

TURBO C PROGRAMMING

tcef;(1)
Turboo C tajccH
1/
2/
3/
4/
5/
6/
7/
8/
9/
10/
11/
12/
13/
14/
15/
16/
17/
18/
19/

ed'gef;
Turbo C odkUpwif0ifa&mufjcif;
Create a New Program File
To Save a Program File
To Close Program File
To Open a Program File
To Quit Turbo C
Turbo C Program Structure
Compile the Source Program
Run the Program
Display the User Screen
Variable Name owfrw
S jf cif;
C Keywords (Resercde Word)
C Data Type Range of Value
C Escape Sequenceds
Arithmetic Operators
Relational and Logical Operators
Constants
Symbolic Constants

1
1
2
2
2
2
2
2
3
3
4
4
4
4
5
6
6
6
7

c

Turbo C

pOf

taMumif ; t&m

uuuGef

pmrsuf E S m

tcef;(2)
DATA INPUT AND OUTPUT
20/
21/
22/
23/
24/
25/
26/
27/
28/
29/
30/
31/
32/
33/
34/
35/
36/
37/
38/
39/
40/
41/
42/
43/

Data Input and Output
Using printf function
Example 2.1
Using scanf function
Example 2.2
Using getchar Function
Example 2.3
Using getche Function
Example 2.4
Using getch function
Examlpe 2.5
Using getc function
Example 2.6
Using putchar function
Example 2.7
Using gets function
Example 2.8
Using put function
Examlpe 2.9
Example 2.10
Example 2.11
Examlpe 2.12
Example 2.13
Example 2.14

8
8
8
10
10
11
11
12
13
14
14
15
15
17
17
18
18
19
19
20
21
22
23
25

*

Turbo C

pOf

taMumif ; t&m

uuuGef

pmrsuf E S m

tcef;(3)
CONTROL STATEMENTS
44/
45/
46/
47/
48/
49/
50/
51/
52/
53/
54/
55/
56/
57/
58/
59/

27
27
28
29
30
32
34
35
36
37
38
39
39
41
41
41

if Statement
Example 3.1
Example 3.2
Example 3.3
Example 3.4
Example 3.5
Example 3.6
goto Statement
Example 3.7
switch Statement
Example 3.8
for Statement
Example 3.9
while Statement
do while Statement
Function

tcef ; (4)
avh u sih f c ef ; rsm;
60/
61/
62/
63/
64/
65/

avhusifhcef;(1)
avhusifhcef;(2)
avhusifhcef;(3)
avhusifhcef;(4)
avhusifhcef;(5)
avhusifhcef;(6)

42
42
43
44
45
45

C

Turbo C

pOf
66/
67/
68/
69/
70/
71/
72/
73/
74/
75/
76/
77/
78/
79/
80/
81/
82/
83/
84/
85/
86/
87/
88/
89/
90/
91/
92/
93/

taMumif ; t&m
avhusifhcef;(7)
avhusifhcef;(8)
avhusifhcef;(9)
avhusifhcef;(10)
avhusifhcef;(11)
avhusifhcef;(12)
avhusifhcef;(13)
avhusifhcef;(14)
avhusifhcef;(15)
avhusifhcef;(16)
avhusifhcef;(17)
avhusifhcef;(18)
avhusifhcef;(19)
avhusifhcef;(20)
avhusifhcef;(21)
avhusifhcef;(22)
avhusifhcef;(23)
avhusifhcef;(24)
avhusifhcef;(25)
avhusifhcef;(26)
avhusifhcef;(27)
avhusifhcef;(28)
avhusifhcef;(29)
avhusifhcef;(30)
avhusifhcef;(31)
avhusifhcef;(32)
avhusifhcef;(33)
avhusifhcef;(34)

uuuGef

pmrsuf E S m
46
47
48
49
50
53
53
54
55
56
57
58
59
61
61
62
62
63
63
64
64
65
65
66
66
67
68
73

i

Turbo C

pOf
94/
95/
96/
97/
98/
99/
100/
101/
102/
103/
104/
105/
106/
107/
108/
109/
110/
111/
112/
113/
114/
115/
116/
117/
118/
119/
120/
121/

taMumif ; t&m
avhusifhcef;(35)
avhusifhcef;(36)
avhusifhcef;(37)
avhusifhcef;(38)
avhusifhcef;(39)
avhusifhcef;(40)
avhusifhcef;(41)
avhusifhcef;(42)
avhusifhcef;(43)
avhusifhcef;(44)
avhusifhcef;(45)
avhusifhcef;(46)
avhusifhcef;(47)
avhusifhcef;(48)
avhusifhcef;(49)
avhusifhcef;(50)
avhusifhcef;(51)
avhusifhcef;(52)
avhusifhcef;(53)
avhusifhcef;(54)
avhusifhcef;(55)
avhusifhcef;(56)
avhusifhcef;(57)
avhusifhcef;(58)
avhusifhcef;(59)
avhusifhcef;(60)
avhusifhcef;(61)
avhusifhcef;(62)

uuuGef

pmrsuf E S m
75
77
78
79
79
80
81
82
83
84
85
85
87
89
90
91
92
93
94
95
96
97
97
98
99
101
102
103

p

Turbo C

pOf
122/
123/
124/
125/
126/
127/
128/
129/
130/
131/
132/
133/
134/
135/

taMumif ; t&m
avhusifhcef;(63)
avhusifhcef;(64)
avhusifhcef;(65)
avhusifhcef;(66)
avhusifhcef;(67)
avhusifhcef;(68)
avhusifhcef;(69)
avhusifhcef;(70)
avhusifhcef;(71)
avhusifhcef;(72)
avhusifhcef;(73)
avhusifhcef;(74)
avhusifhcef;(75)
avhusifhcef;(76)

uuuGef

pmrsuf E S m
104
105
109
110
112
113
114
115
116
117
118
119
119
120

Contents

1

TurboC

uuuGef

TURBO C PROGRAMMING

tcef;(1)
Turboo C tajccH

ed'gef;
1/

Turboc C Program qdkonfrSm Function rsm;jzifhzGJUpnf;wnfaqmufxm;NyD;
Program Statement rsm;ud k tpD t pOf t vd k u f ajz&S i f ; ay;aaom Procedural
Programming Language wpfrsdK;jzpfygonf/ C Program wpfckwGif Function wpfck
(odrYk [kw)f wpfcx
k ufyNkd y;D yg&SEd ikd yf gonf/ tenf;qH;k main( ) wpfcyk g&S&d ygrnf/ Turbo
C Program wpfckudk Run vdkufaomtcg main( ) udk pwiftvkyfvkyfNyD; 4if;rSwqifh
a&;xm;aom ñTef;Mum;csufrsm;udk Munfh&Ippfaq;NyD; wpfjcm;aom Function rsm;qDudk

vdktyfovdk ac:,lNyD; vdktyfaomvkyfaqmifcsufrsm;udk aqmif&Gufay;rnfjzpfygonf/
main( ) onf Turbo C Program wpfcw
k iG f rygrjzpfaom Function wpfcjk zpfygonf/
Turbo C odkY pwif0ifa&mufjcif;
2/
uGefysLwm Monitor Screen rS MS DOS Prompt ( C Prompt ) ( C:\> )
ay:aecsed w
f iG f Keyboard rS CD TC ½du
k x
f nfNh y;D Enter Key udk ESyd yf g/ xdt
k cg Monitor
Screen wGif C:\TC\> ay:vmrnf/ xdaYk emuf CD Bin udx
k yf&u
kd Nf y;D Enter key udEk ydS yf g/
qufí Monitor Screen wGif C:\TC\BIN\> ay:vmrnf/ xdaYk emuf TC udx
k yf½u
kd Nf y;D
Enter Key udk ESdyfygu Turbo C Program udk pwifa&;om;Edkif&ef Turbo C Editor
Screen ay:vmrnf/yHk(1)
File Edit Search Run Complile Debug Project Options Window Help

Message
F1 Help F10 Menu

yHk(1)

Contents

TurboC

2

uuuGef

Create a New Program File
3/
Keyboard rS Alt ESihf F key udk wGE
J ydS yf g/ ay:vmaom File pulldown menu rS
New a½G;cs,í
f Enter key udEk ydS yf g/ Program a&;om;Edik &f ef Turbo C Editor windows
ay:vmygrnf/
To Save a Program File
4/
Keyboard rS F2 key udk ESdyfyg/ (odkYr[kwf) Alt ESifh F udk wGJESdyfí ay:vmaom
File pulldown menu rS Save udk a½G;cs,fí Enter key udkESdyfyg/ ay:vmaom Save
file As windows rS Save File As text box wGif File name udk ½du
k x
f nfNh y;D Enter key
udk ESdyfyg/
To Close a Progam File
5/
Keyboard rS Alt ESihf F3 key udk wGí
J ESyd yf g/ (odrYk [kw)f Alt ESihf W udk wGEJ ydS yf g/
ay:vmaom Window pulldown menu rS Close udka½G;cs,fí Enter key udkESdyfyg/
To Open a Program File
6/
Keyboard rS F3 udkESdyfyg/ (odkYr[kwf) Alt ESifh F udk wGJíESdyfyg/ ay:vmaom
File pulldown rS Open udk a½G;cs,fí Enter key udkESdyfyg/ ay:vmaom Open File
Windows rS zGifhvdkaom File udk &SmazGa½G;cs,fí Enter key udkESdyfyg/
To Quit Turbo C
7/
Keyboard rS Alt ESifh X udk wGJíESdyfyg/ (odkYr[kwf) Aalt ESifh F udk wGJíESdyfyg/
ay:vmaom File pulldown menu rS Quit udk a½G;cs,fí Enter udk ESdyfyg/
Turbo C Program Structure
8/
Turbo C Program \ Structure wnfaqmufyHkrSm atmufygtwdkif; zGJUpnf;
wnfaqmufxm;ygonfHeader file declaration
Programmar define statement
main( )
{
statement1;

Contents

TurboC

3

uuuGef

statement2;
------------;
}
Turbo C Program udk pwifa&;om;&eftwGuf yxrOD;pGm Header File udk
aMujimay;&ygrnf/ Oyrm Stamdard Input output twGuf Header File udk
#include<stdio.h> ponf[ak Mujimay;&ygrnf/ Program twGuf rSwc
f surf sm; a&;om;
vdkygu /* */ twGif;wGif a&;om;toHk;jyK&ygrnf/ Oyrm- /* Teach yourself Turbo
C */ [ka&;om;&ygrnf/ ¤if;pmaMumif;twGuf C compiler u vkyfaqmifrI rjyKvkyfbJ
ausmo
f mG ;ygrnf/ Program define statement ( symbolic constant ) toH;k jyKvykd gu
Symbolic constant udk Define owfrw
S af Mujimay;&ygrnf/ Symbolic constant name
udk Define owfrSwf&efwGif Symbolic constant name udk pmvHk;tBuD;jzifh a&;om;
owfrSwfay;&ygrnf/ Oyrm- DEFINE PI 3.141593 [k aMujimay;&rnf/ xdkYaemuf
main ( ) udk a&;om;aMujimay;&ygrnf/ main ( ) \aemufwGif semicolon(;) jzifh
ydw&f efrvdyk g/ main( ) \atmufwiG f Program pwiftvkyf vkyaf qmif&eftwGuf Open
curly bracket { jzifah &;om;&ygrnf/ ¤if;aemuf toH;k jyKrnf Statement rsm;udk a&;om;
ay;&ygrnf/ Statement rsm;udk a&;om;&mwGif Statement wpfcNk y;D qH;k wdik ;f Semicolon
(;) jzifh ydwfay;&ygrnf/ Statement rsm;a&;om; NyD;ygu Program vkyfaqmifcsuf
NyD;qHk;aMumif; Close curly bracket } jzifh ydwfay;&ygrnf/

Compile the source program
9/
Turbo C Program wpfcka&;om;í Program wGif error &Sd^r&Sd ppfaq;&ef
vdktyfygonf/ error r&SdrSom ¤if; Program udk Run í&Edkifygrnf/ error &Sdygu ¤if;
Program udk Run í&rnfr[kwy
f g/ Program udk Compile jyKvyk &f eftwGuf Compile
vkyfvdkaom Program udk zGifhxm;yg/ Alt ESifh F9 udk wGJíESdyfyg/ (odkYr[kwf) Alt ESifh C
udw
k í
JG ESyd yf g/ ay:vmaom Compile pulldown menu rS Compile udk a½G;cs,í
f Enter
udk ESdyfyg/
Run the Program
10/ Run vdak om Program udzk iG x
hf m;yg/ Ctrl ESihf F9 udk wGí
J ESyd yf g/ (odrYk [kw)f Alt
ESifh R udkwGJESdyfyg/ ay:vmaom Run pulldwon menu rS Run udka½G;cs,fí Enter udk
ESyd yf g/

Contents

4

TurboC

uuuGef

Display the User Screen
11/ Turbo C Program udk Run Ny;D í Program \ tajzudk Munfv
h ykd gu Keyboard
rS Alt ESifh F5 key udk wGJíESdyfyg/ xdktcg Program \ tajzudk jyoay;ygrnf/ Editor
Screen udk jyefomG ;vdy
k gu Keyboard rS ckvw
k w
f pfcck u
k kd ESyd yf g/ Program a&;xm;aom
Editor Screen odkYjyefa&mufoGm;yge 2rnf/

Variable Name owfrSwfjcif;
12/ Varible qdo
k nfrmS C Program wGif Data value rsm;odr;f xm;&ef toH;k jyKaom
Storage ae&mwpfcjk zpfygonf/ Variable Name owfrw
S af y;&mü pmvH;k rsm;(Letters)?
*Pef;rsm; (Digits)? ESifh Underscore( _ ) Character rsm;jzifh owfrSwfay;Edkifygonf/
odaYk omf Variable Name \ a&SUqH;k tu©&monf *Pef;? tEkwv
f u©Pm? Space? Specil
character( " ) rsm; toHk;jyKír&yg/ xdkYtjyif Variable Name owfrSwf&mwGif C
Keywords ( Reserved word ) rsm;udkvnf; owfrSwfay;ír&yg/
C Keywords ( Reserced word )
13/ atmufaz:jypmvHk;rsm;onf Turbo C Program wGif Reserced word tjzpf
owfrw
S af om C Keyword rsm;jzpfygonf/ ¤if;wdu
Yk kd C Program wGif Variable name
tjzpftoHk;jyKír&yg/ ¤if;pmvHk;rsm;udk Program wGif a&;om;ygu Reserced word
rSef;odatmif tjzLa&mifpmvHk;rsm;tjzpfjyoay;ygonf/
auto
conts
else
for
int
register
static
unsigned

break
continue
enum
fortran
interrupt
return
struct
void

case
default
extern
goto
lonh
short
switch
volatile

cdecl
do
far
huge
near
signed
typedef
while

char
double
float
if
pascal
sizeof
union

C Data Type Range of Values
14/ Turbo C language wGif data type trsKd ;rsKd ;&Syd gonf/ Data type toH;k jyKaom
tcg data type format wlnrD o
S m Program onf tajzrSe&f &Syd grnf/ Data type format

Contents

5

TurboC

uuuGef

wlnDrIr&Sdygu Program \ tajzonf trSef&&Sdrnfr[kwfyg/ Turbo C basic data
type rsm;udk atmufyg Z,m;twdkif;jzpfygonfType Name
char
siged char
unsigned
int
singned int
unsigned int
long int
unsigned long int
float
double
long double

Format
%c
%d
%d

%ld

%f
%lf
%Lf

Range of Value
single character
-128 to 127
0 to 255
integerr quaantity
-32,768 to 32,768
0 to 65535
-2,147,483,648 to
2,147,483,648
0 to 4,294,967,295
3.4E to 3.4E+38
1.7E-308 t0 1.7E+308
3.4E-4932 to 3.4E+3942

C Escape Sequences
15/ Turbo C Program wGif toHk;jyKaom Escape Sequences rsm;rSm atmufyg
twdkif;jzpfygonfEscape Sequences
\a
\b
\f
\n
\r
\t
\'
\"
\?
\0
\\

Application
alert (bell)
backspace
form feed
new line
carriage return
tab
single quotation mark
double quotation maark
question mark
null (zero) character
baackslash

Contents

6

TurboC

uuuGef

Arithmetic Operators
16/ Turbo C Program wGif toH;k jyKaom Arithmetic Operators rsm;rSm atmufyg
twdkif;jzpfygonf+
Addition ( taygif; )
Subtraction ( tEkwf )
*
Multiplication ( tajr§muf )
/
Division ( tpm; )
%
Modulus ( t<uif; )
++
Incrementing ( wpfckpDwdk; )
-Decrementing ( wpfckpDavsmh )
Relational and Logical Operators
17/ Turbo C Program wGif toHk;jyKaom Relational and Logical Operators
rsm;rSm atmufyg twdkif;jzpfygonf<
<=
>
>=
==
!=

less than
less than equal to
greater than
greater than equal to
equal to
not equal to

Constants
18/ C Program wGif rajymif;vJítNru
J ed ;f aojzpfaeaomwefz;kd rsm;udk Constants
(udef;ao)[kac:ygonf/ C Prograam wGif toHk;jyKaom Constants (4)rsdK;&Sdygonf/
¤if;wdrYk mS Character constans? Integer constans? Floating point constans ESihf String
constans wdjYk zpfygonf/
(u) Character Constans qdo
k nfrmS Variable wpfcw
k iG f Single code( ' ')
jzpf Assign jyKvyk x
f m;aom Character value udq
k ykd gonf/ Oyrm- Ch
(c)

= 'A'
Integer constans qdo
k nfrmS Variable wpfcw
k iG f Assign vkyx
f m;aom
udef;*Pef;wefzdk;rsm; (long, short, signed, unsigned fixed value)

Contents

TurboC

(* )
(C)

7

uuuGef

udq
k v
kd ykd gonf/ Integer constans wGif Decimal constants(base 10),
Octal constans (base 8), Hexadecimal constants (base 16) [lí
(3)rsdK;xyfrHcGJjcm;xm;ygonf/ Decimal constants qdkonfrSm okn rS
9 *Pef;rsm;udkqdkvdkygonf/ Decimal constants udk *Pef;(1)vHk;
(odrYk [kw)f (1) vH;k xufyí
kd owfrw
S af y;Edik yf gonf/ odaYk omf *Pef;(1)vH;k
xufydkygu xdyfqHk;*Pef;onf oknjzpfír&yg/ Decimal constans
udk owfrSwfay;aomtcgwGif comma( , )? 'ór? uGufvyf (space)?
Upper bound limit ausmí
f toH;k rjyKEikd yf g/ Octal constans qdo
k nfrmS
ok n rS 7 *Pef ; rsm;ud k q d k v d k y gonf / Octal constans value
owfrw
S af omtcg Octal constans rSe;f odatmif xdyq
f ;kH *Pef;udk okn
tjzpf owfrSwfay;&ygonf/ (Oyrm- 0556 )/ CHexadecimal
constans qdkonfrSm okn rS 9 *Pef;rsm;ESifhtwl A rS F pmvHk;rsm;udk
qdkvdkygonf/ Hexadecimaal constans value owfrSwfay;aomtcg
Hexadecimaal constans rSe;f od&adS tmif xdyq
f ;kH tu©&m ESpv
f ;kH udk 0x
(odkYr[kwf) 0X tjzpf owfrSwfay;&ygonf/ Oyrm- 0x34ca
Floating point constans qd k o nf r S m Base 10 ud k t ajccH a om
'órudef; (real number) rsm;udkqdkygonf/ Oyrm- 12.5
String constants qdo
k nfrmS variable contans owfrw
S af y;aomtcg
Double quotation mark (" ") xJwGif a&;xm;aom tu©&mrsm;udk
qdv
k ykd gonf/ Oyrm- "Computer Department"

Symbolic Constants
19/ Symbolic Constants qdkonfrSm Character tpkwpfck (odkYr[kwf) Number
value wpfck (odr
Yk [kw)f Statement wpfcu
k kd trnfwpfct
k jzpf tpm;ay;xm;aom Name
wpfcu
k q
kd v
kd ykd gonf/ symbolic constants rsm; aMujimay;vdyk gu Program \ tpwGif
Define jyKvkyfay;&ygrnf/ Oyrm- #define PRINTX printf("%d\n",x)? #define PI
3.141593 ponfjzifhaMujimay;&ygrnf/ define statement \aemufwGif semicolon
(;) xnfha&;&m rvdkyg/

Contents

TurboC

8

uuuGef

tcef;(2)
DATA INPUT AND OUTPUT
Data Input and Output
20/ C program wGif Data rsm; toGif;txkwfjyKvkyf&ef t"duusaom Function
(6) ck&Sdygonf/ ¤if;wdkYrSm scanf( )? printf( )? getchar( )? putchar( )? gets( )? puts( )
wdkYjzpfMuygonf/ scanf( ) ESifh printf( ) udk Character? Numeric value odkYr[kwf
String rsm; tm;vH;k udk Input / Output jyKvy
k af y;Edik yf gonf/ getchar( ) ESihf putchar( )
udk Character wpfckcsif;udk Input / Output jyKvkyfvdkaomtcgwGiftoHk;jyKygonf/
gets( ) ESihf puts( ) udk String rsm;udo
k m Input / Output jyKvyk &f eftwGuf toH;k jyKygonf/
Using printf function
21/ Turbo C Program wGif Output data rsm;udk Standard output device rSm
jyovdkygu printf function udktoHk;jy&ygonf/
Syntax
printf("output format", <list of variable>);
Output format qdo
k nfrmS Formatting az:jyvdak om String trsKd ;tpm; jzpfNy;D
List of variable qdo
k nfrmS Output jyKvyk v
f akd om Data variable names jzpfygonf/
Output format a&;om;&mwGif toHk;jyKxm;aom Variable ESifh Data Type format
wdkYonf udkufnDrIjzpf&ygrnf/ ¤if;tjyif Data type format \ a&SUwGif Percent sing
(%) udx
k nfo
h iG ;f a&;ay;&ygrnf/ Oyrm- character data type udk toH;k jyKygu Output
format wGif %c [lí¤if;? Integer data type udk toHk;jyKygu %d [lí¤if;? Float
point data type udk toHk;jyKygu %f [lí¤if;? String data type udk toHk;jyKygu %s
[lí a&;om;ay;&ygrnf/Oyrm- printf("Character %c ",ch);
Example 2.1

22/

/* Using printf function */
#include<stdio.h>
main( )
{

Contents

9

TurboC

uuuGef

char smplch;
int smplnum;
smplch = 'a'; smplnum = 9;
printf(“The samples are %c and %d.\n”,smplch,smplnum);
}

txufyg Example 2.1 Program udkavhvmygu
(u) /* */ twGif; a&om;xm;aompmaMumif;onf Program twGuf
rSwcf suaf &;om;jcif;jzpfygonf/ ¤if;pmaMumif; twGuf Program rS rnfoYkd
vkyfcsufrS vkyfaqmifrIrjyKvkyfbJ ausmfoGm;ygrnf/
(c ) Standard input output tuGuf Header file udkaMujimay;jcif; jzpfyg
onf/
(* ) main function udk aMujimay;jcif;jzpfygonf/
(C) Program udk pwifajz&Sif;&eftwGuf Open curly bracket ({)
udktoHk;jyKNyD; aMujimay;jcif;jzpfygonf/
(i ) smplch variable name udk Data type char tjzpf aMujimay;jcif;
jzpfygonf/
(p ) smplnum variable name udk Data type int tjzpf aMujimay;jcif;
jzpfygonf/
(q) smplch variable name xJodkY Character contants 'a' udk Assign
jyKvkyfay;jzpfygonf/
(Z ) smplnum xJodkY Integer contants 9 udk Assign jyKvkyfay;jcif;
jzpfygonf/
(ps ) printf output function toHk;jyKNyD; Computer Screen wGif The
sample are a and 9. ay:atmifjyKvkyfay;jcif;jzpfygonf/
(n) vkyfaqmifcsufrsm; NyD;qHk;aMumif; Close curly bracket (}) udk aMujim
ay;jcif;jzpfygonf/
txyfyg Program Example 1 udk Run vdkufrnfqdkygu Screen wGif The
sample a and 9. [kay:vmygrnf/

Contents

TurboC

10

uuuGef

Using scanf function
23/ Keyboard rS uGefysLwmxJodkY Data rsm;xnfhoGif;vdkygu Scanf function udk
toH;k jyK&ygonf/
Syntax
scanf("Input format", <list of variable>);
Input format qdo
k nfrmS Format twGuf conversion character xnfah y;&ef
jzpfNy;D List of variable qdo
k nfrmS Input jyKvyk v
f akd om Data variable item names \
Address jzpfygonf/ Output format twGuf conversion character \a&SUwGif percent
sing (%) xnf h í a&;NyD ; ? Variable item name \a&S U wG i f ampersant (&)
udx
k nfí
h a&;ay;&ygrnf/ Oyrm- scanf("%d",&num);
Example 2.2
24/ /*scanf( )*/
#include<stdio.h>
main( )
{
int num;
printf(“\nEnter Number “);
scanf(“%d”,&num);
printf(“You Type number %d”,num);
}

txufyg Example 2.2 program udk avhvmrnfqdkygu
(u) /* */ twGif; a&om;xm;aompmaMumif;onf Program twGuf
rSwcf suaf &;om;jcif;jzpfygonf/ ¤if;pmaMumif; twGuf Program rS rnfoYkd
vkyfcsufrS vkyfaqmifrIrjyKvkyfbJ ausmfoGm;ygrnf/
(c ) Standard input output tuGuf Header file udkaMujimay;jcif; jzpfyg
onf/
(* ) main function udk aMujimay;jcif;jzpfygonf/

Contents

11

TurboC

(C)
(i )
(p )
(q)

(Z )

uuuGef

Program udk pwifajz&Sif;&eftwGuf Open curly bracket ({) udk

toHk;jyKNyD; aMujimay;jcif;jzpfygonf/
num variable name udk Data type int tjzpf aMujimay;jcif; jzpfygonf/
printf function udk toHk;jyKNyD; Enter Number qdkonfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
scanf function udk toHk;jyKNyD; Keyboard rS½kdufxnfhrnfh num udk
vufc&H eftwGujf zpfygonf/ %d onf integer data type format jzpfNy;D ?
&num onf num variable name \ Address jzpfygonf/
printf function udk toHk;jyKNyD; Program Run í &&Sdvmrnfhtajzudk
jyojcif;jzpfygonf/ %d onf integer data type format jzpfNyD;? num
\ wefzdk;jzpfygonf/

txufyg Program udk Run rnfqykd gu uGeyf sLwm Screen wGif Enter Number
[k Data udk Keyboard ½dkufxnfhay;&ef today;aom pmaMumif;ay:vmrnf/ xdktcg
Keyboard rS number wpfckckudk ½dkufxnfhNyD; Enter key udk ESdyfyg/ Oyrm 5 *Pef;udk
½d k u f x nf h N yD ; Enter key ud k ES d y f y gu Program Run oG m ;NyD ; Editor screen
odkYjyefa&mufoGm;rnf/ alt + F5 udkESdyfygu uGefysLwm Screen wGif You Type number
5 [k jyoay;ygrnf/ Editor scrren odYk jyefo
f mG ;vdyk gu Keyboard rS any key wpfcck u
k kd
ESyd yf g/
Using getchar Function
25/ Character wpfcck si;f zwfvakd omtcgwGif getchar function udk toH;k jyKygonf/
26/

Example 2.3
/*getchar( )*/
#include<stdio.h>
main( )
{
char ch;
printf(“\nEnter Character “);

Contents

TurboC

12

uuuGef

ch=getchar( );
printf(“\nYou Type Character %c “,ch);
}

txufyg Example 2.3 program udk avhvmrnfqdkygu
(u) /* */ twGif; a&om;xm;aompmaMumif;onf Program twGuf
rSwfcsufa&;om;jcif;jzpfygonf/
(c ) Header file udkaMujimay;jcif; jzpfygonf/
(* ) main function udk aMujimay;jcif;jzpfygonf/
(C) Program udk pwifajz&Si;f &eftwGuf Open curly bracket ({) udk toH;k
jyKNyD; aMujimay;jcif;jzpfygonf/
(i ) ch variable name udk Data type char tjzpf aMujimay;jcif;jzpfygonf/
(p ) printf function udk toHk;jyKNyD; Enter Number qdkonfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
(q) getchar function udk toH;k jyKNy;D Keyboard rS½u
dk x
f nfah om character
udk ch xJodkY Assing jyKvkyfay;ygonf/
(Z ) getchar jzifh vufcx
H m;aom character wefz;kd udk jyefvnfjyo&eftwGuf
printf function udk toHk;jyKxm;ygonf/
txufyg Program udk Run rnfqykd gu uGeyf sLwm Screen wGif Enter Number
[k Data udk Keyboard ½dkufxnfhay;&ef today;aom pmaMumif;ay:vmrnf/ xdktcg
Keyboard rS character wpfcc
k u
k kd ½du
k x
f nfNh y;D Enter key udk ESyd yf g/ Oyrm A pmvH;k udk
½d k u f x nf h N yD ; Enter key ud k ES d y f y gu Program Run oG m ;NyD ; Editor screen
odjYk yefa&mufomG ;rnf/ Alt + F5 udEk ydS yf gw uGeyf sLwm Screen wGif You Type Character
A [k jyoay;ygrnf/
Using getche Function
27/ Character wpfckcsif; zwfvdkaomtcgwGif getche function udk toHk;jyKEdkifyg
onf/ getche function udk toH;k jyKaomtcg Data udk Keyboard rS ½du
k x
f nfv
h u
kd af om
tcgwGif Data udk ½dkufxnfhvdkufonfESifh Enter key udk ESdyf&efrvdkyJ uGefysLwmrSm

Contents

TurboC

13

uuuGef

qufvufí tvkyfvkyfaqmifoGm;ygonf/ getche function toHk;jyKvdkygu Header
file wGif #include<conio.h> [k aMujimay;&ygrnf/
Example 2.4
28/ /*Example 2.4 getche( )*/
#include<stdio.h>
#include<conio.h>
main( )
{
char ch;
printf(“\nEnter Character “);
ch=getche( );
printf(“\nYou Type Character %c “,ch);
}

txufyg Example 2.4 program udk avhvmrnfqdkygu
(u) /* */ twGif; a&om;xm;aompmaMumif;onf Program twGuf
rSwfcsufa&;om;jcif;jzpfygonf/
(c ) Header file udkaMujimay;jcif; jzpfygonf/
(* ) main function udk aMujimay;jcif;jzpfygonf/
(C) Program udk pwifajz&Si;f &eftwGuf Open curly bracket ({) udk toH;k
jyKNyD; aMujimay;jcif;jzpfygonf/
(i ) ch variable name udk Data type char tjzpf aMujimay;jcif; jzpfygonf/
(p ) printf function udk toHk;jyKNyD; Enter Number qdkonfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
(q) getche function udk toH;k jyKNy;D Keyboard rS½u
dk x
f nfah om character
udk ch xJodkY Assing jyKvkyfay;ygonf/
(Z ) getche jzifh vufcx
H m;aom character wefz;kd udk jyefvnfjyo&eftwGuf
printf function udk toHk;jyKxm;ygonf/

Contents

TurboC

14

uuuGef

txufyg Program udk Run rnfqykd gu uGeyf sLwm Screen wGif Enter Number
[k Data udk Keyboard ½dkufxnfhay;&ef today;aom pmaMumif;ay:vmrnf/ xdktcg
Keyboard rS character wpfcc
k u
k kd ½du
k x
f nfah y;vdu
k yf gu Program Run oGm;Ny;D Editor
screen odkYjyefa&mufoGm;rnf/ Oyrm A pmvHk;udk ½dkufxnfhvdkufygu Program Run
oGm;NyD; Editor screen odkYjyefa&mufoGm;rnf/ Alt + F5 udkESdyfygw uGefysLwm Screen
wGif You Type Character A [k jyoay;ygrnf/
Using getch function
29/ Character wpfckcsif; zwfvdkaomtcgwGif¤if; Program Run NyD; &&Sdvmaom
tajzwdk uGefysLwm Screen wGif jyoay;&mwGif¤if; getch function udk toHk;jyKEdkifyg
onf/ getch function udk toH;k jyKaomtcg Data udk Keyboard rS ½du
k x
f nfv
h u
kd af om
tcgwGif Input Data udk uGefysLwm Screen wGif jyojcif;r&SdyJ Output Data udkom
jyoay;ygonf/ Data ½du
k x
f nfNh y;D Enter key udk ESyd &f efrvdyk J uGeyf sLwmrSm qufvufí
tvkyfvkyfaqmifoGm;ygonf/ getche function toHk;jyKvdkygu Header file wGif
#include<conio.h> [k aMujimay;&ygrnf/
Example 2.5
30/ /* Example 2.5 getch( )*/
#include<stdio.h>
#include<conio.h>
main( )
{ char ch;
printf(“\nEnter Character “);
ch=getch( );
printf(“\nYou Type Character %c",ch);
getch( );
}

txufyg Example 2.5 program udk avhvmrnfqdkygu
(u) /* */ twGif; a&om;xm;aompmaMumif;onf Program twGuf
rSwfcsufa&;om;jcif;jzpfygonf/

Contents

15

TurboC

(c )
(* )
(C)
(i )
(p )
(q)
(Z )
(ps)

uuuGef

Header file udkaMujimay;jcif; jzpfygonf/
main function udk aMujimay;jcif;jzpfygonf/
Program udk pwifajz&Si;f &eftwGuf Open curly bracket ({) udk toH;k

jyKNyD; aMujimay;jcif;jzpfygonf/
ch variable name udk Data type char tjzpf aMujimay;jcif; jzpfygonf/
printf function udk toHk;jyKNyD; Enter Number qdkonfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
getch function udk toHk;jyKNyD; Keyboard rS½kdufxnfhaom character
udk ch xJodkY Assing jyKvkyfay;ygonf/
getch jzifh vufcx
H m;aom character wefz;kd udk jyefvnfjyo&eftwGuf
printf function udk toHk;jyKxm;ygonf/
Program Run í &&Sdvmaom tajzudk uGefysLwm Screen wGif
jyoay;&mtwGuf getch function udk toHk;jyKygonf/

txufyg Program udk Run rnfqykd gu uGeyf sLwm Screen wGif Enter Number
[k Data udk Keyboard ½dkufxnfhay;&ef today;aom pmaMumif;ay:vmrnf/ xdktcg
Keyboard rS character wpfckckudk ½dkufxnfhay;vdkufygu Program Run oGm;NyD;
&&Sv
d maom tajzudk uGeyf sLwm screen wGif You Type Character A [k jyoay;ygrnf/
Oyrm A pmvHk;udk ½dkufxnfhvdkufygu Program Run oGm;NyD; You Type Character A
[k jyoay;ygrnf/ Editor screen odkYjyefvdkygu keyboard rS cvkwfwpfckckudkESdyfyg/
Using getc function
31/ Character wpfcck si;f zwfvakd omtcgwGif getc function udk toH;k jyKEikd yf gonf/
getc function udk toH;k jyKaomtcg Data udk Keyboard rS ½du
k x
f nfv
h u
kd af om tcgwGif
Data ½du
k x
f nfNh y;D Enter key udk ESyd rf o
S m uGeyf sLwmrSm qufvufí tvkyf vkyaf qmif
oGm;ygonf/ getc function toH;k jyKvykd gu function argument wGif stdin udk xnfí
h
aMujimay;&ygrnf/ Oyrm- getc(stdin)
Example 2.6
32/ /* Example 2.6 getch( )*/
#include<stdio.h>

Contents

TurboC

16

uuuGef

main( )
{
char ch;
printf(“\nEnter Character “);
ch=getc(stdin);
printf(“\nYou Type Character %c “,ch);
}

txufyg Example 2.6 program udk avhvmrnfqdkygu
(u) /* */ twGif; a&om;xm;aompmaMumif;onf Program twGuf
rSwfcsufa&;om;jcif;jzpfygonf/
(c ) Header file udkaMujimay;jcif; jzpfygonf/
(* ) main function udk aMujimay;jcif;jzpfygonf/
(C) Program udk pwifajz&Si;f &eftwGuf Open curly bracket ({) udk toH;k
jyKNyD; aMujimay;jcif;jzpfygonf/
(i ) ch variable name udk Data type char tjzpf aMujimay;jcif;jzpfygonf/
(p ) printf function udk toHk;jyKNyD; Enter Number qdkonfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
(q) getc function udk toHk;jyKNyD; Keyboard rS½kdufxnfhaom character
udk ch xJodkY Assing jyKvkyfay;ygonf/
(Z ) getc jzifh vufcx
H m;aom character udk jyefvnfjyo&eftwGuf printf
function udk toHk;jyKxm;ygonf/
txufyg Program udk Run rnfqykd gu uGeyf sLwm Screen wGif Enter Number
[k Data udk Keyboard ½dkufxnfhay;&ef today;aom pmaMumif;ay:vmrnf/ xdktcg
Keyboard rS character wpfcc
k u
k kd ½du
k x
f nfNh y;D Enter key udk ESyd yf g/ Oyrm A pmvH;k udk
½dkufxnfhNyD; Enter key udk ESdyfygu Program Run oGm;NyD; Editor screen odkY
jyefa&mufomG ;rnf/ Alt + F5 udEk ydS yf gw uGeyf sLwm Screen wGif You Type Character
A [k jyoay;ygrnf/

Contents

TurboC

17

uuuGef

Using putchar function
33/ Character wpfvHk;csif;udk uGefysLwm Screen wGif jyovdkaomtcg putchar
function udk toHk;jyKygonf/ Oyrm- putchar(ch)
Example 2.7
34/ /* Example 2.7 putchar( )*/
#include<stdio.h>
main( )
{
char ch;
printf(“\nEnter Character “);
scanf(“%c”,&ch);
putchar(ch);
}

txufyg Example 2.7 program udk avhvmrnfqdkygu
(u) /* */ twGif; a&om;xm;aompmaMumif;onf Program twGuf
rSwfcsufa&;om;jcif;jzpfygonf/
(c ) Header file udkaMujimay;jcif; jzpfygonf/
(* ) main function udk aMujimay;jcif;jzpfygonf/
(C) Program udk pwifajz&Si;f &eftwGuf Open curly bracket ({) udk toH;k
jyKNyD; aMujimay;jcif;jzpfygonf/
(i ) ch variable name udk Data type char tjzpf aMujimay;jcif;jzpfygonf/
(p ) printf function udk toHk;jyKNyD; Enter Number qdkonfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
(q) scanf function udk toHk;jyKNyD; Keyboard rS½kdufxnfhaom character
udk vufcHjcif;jzpfygonf/
(Z ) scanf function jzifh vufcHxm;aom character udk jyefvnfjyo&ef
twGuf putchar function udk toHk;jyKxm;ygonf/

Contents

TurboC

18

uuuGef

txufyg Program udk Run rnfqykd gu uGeyf sLwm Screen wGif Enter Number
[k Data udk Keyboard ½dkufxnfhay;&ef today;aom pmaMumif;ay:vmrnf/ xdktcg
Keyboard rS character wpfcc
k u
k kd ½du
k x
f nfNh y;D Enter key udk ESyd yf g/ Oyrm A pmvH;k udk
½dkufxnfhNyD; Enter key udk ESdyfygu Program Run oGm;NyD; Editor screen odkY
jyefa&mufomG ;rnf/ Alt + F5 udEk ydS yf gw uGeyf sLwm Screen wGif You Type Character
A [k jyoay;ygrnf/
Using gets function
35/ Keyboard rS uGefysLwmxJodkY String Input Data rsm;xnfhoGif;vdkygu gets
function udk toHk;jyK&ygonf/
Example 2.8
36/ /* Example 2.8 gets( )*/
#include<stdio.h>
main( )
{
char str[80];
printf(“\nEnter a String “);
gets(str);
printf(“%s”,str);
}

txufyg Example 2.8 program udk avhvmrnfqdkygu
(u) /* */ twGif; a&om;xm;aompmaMumif;onf Program twGuf
rSwfcsufa&;om;jcif;jzpfygonf/
(c ) Header file udkaMujimay;jcif; jzpfygonf/
(* ) main function udk aMujimay;jcif;jzpfygonf/
(C) Program udk pwifajz&Si;f &eftwGuf Open curly bracket ({) udk toH;k
jyKNyD; aMujimay;jcif;jzpfygonf/
(i ) str variable name udk Data type char array pmvHk;a& 80 tjzpf
aMujimay;jcif; jzpfygonf/

Contents

19

TurboC

(p )
(q)
(Z )

uuuGef

printf function udk toHk;jyKNyD; Enter Number qdkonfh today;

pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
gets function udk toH;k jyKNy;D Keyboard rS½u
dk x
f nfah om string wpfcu
k kd
str array wGif assing vkyfívufcHjcif;jzpfygonf/
gets function jzifh vufcHxm;aom string udk jyefvnfjyo&ef twGuf
printf function udk toHk;jyKxm;ygonf/

txufyg Program udk Run rnfqykd gu uGeyf sLwm Screen wGif Enter Number
[k Data udk Keyboard ½dkufxnfhay;&ef today;aom pmaMumif;ay:vmrnf/ xdktcg
Keyboard rS string wpfckckudk ½dkufxnfhNyD; Enter key udk ESdyfyg/ Oyrm Defence
Service Computer Department udk ½dkufxnfhNyD; Enter key udk ESdyfygu Program
Run oGm;NyD; Editor screen odkY jyefa&mufoGm;rnf/ Alt + F5 udkESdyfygw uGefysLwm
Screen wGif Defence Service Computer Department [k jyoay;ygrnf/
Using puts function
37/ String Output data rsm;udk Standard output device rSm jyovdkygu puts
function udt
k oH;k jy&ygonf/
Example 2.9
38/ /* Example 9 puts( )*/
#include<stdio.h>
main( )
{ char str[80];
printf(“\nEnter a String “);
gets(str);
puts(str);
}

txufyg Example 2.9 program udk avhvmrnfqdkygu
(u) /* */ twGif; a&om;xm;aompmaMumif;onf Program twGuf
rSwfcsufa&;om;jcif;jzpfygonf/

Contents

TurboC

(c )
(* )
(C)
(i )
(p )
(q)
(Z )

20

uuuGef

Header file udkaMujimay;jcif; jzpfygonf/
main function udk aMujimay;jcif;jzpfygonf/
Program udk pwifajz&Si;f &eftwGuf Open curly bracket ({) udk toH;k

jyKNyD; aMujimay;jcif;jzpfygonf/
str variable name udk Data type char array pmvHk;a& 80 tjzpf
aMujimay;jcif; jzpfygonf/
printf function udk toHk;jyKNyD; Enter Number qdkonfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
gets function udk toH;k jyKNy;D Keyboard rS½u
dk x
f nfah om string wpfcu
k kd
str array xJodkY assing vkyfívufcHjcif;jzpfygonf/
gets function jzifh vufcHxm;aom str xJrS string character rsm;udk
uGeyf sLwm screen wGif jyo&ef twGuf puts function udk toH;k jyKxm;
ygonf/

txufyg Program udk Run rnfqykd gu uGeyf sLwm Screen wGif Enter Number
[k Data udk Keyboard ½dkufxnfhay;&ef today;aom pmaMumif;ay:vmrnf/ xdktcg
Keyboard rS string wpfckckudk ½dkufxnfhNyD; Enter key udk ESdyfyg/ Oyrm Defence
Service Computer Department udk ½dkufxnfhNyD; Enter key udk ESdyfygu Program
Run oGm;NyD; Editor screen odkY jyefa&mufoGm;rnf/ Alt + F5 udkESdyfygw uGefysLwm
Screen wGif Defence Service Computer Department [k jyoay;ygrnf/
Example 2.10
39/ /* Exercise 2.10 The sum of the given two number */
#include<stdio.h>
main()
{ int a,b,sum; /*Variable Declaration */
a=5; b=6; /* Assignment Statement */
sum = a + b;
printf(“The sum of the given two number is %d.”);
}

Contents

TurboC

21

uuuGef

txufyg Exercise 1 program udk avhvmrnfqdkygu
(u) a, b ESihf sum variable name udk Data type int tjzpfaMujimay;jcif;jzpf
ygonf/
(c ) a xJodkY integer constants number 5 udk¤if;? b xJodkY integer
constants number 6 udk Assign jyKvkyfay;onf/
(* ) sum xJodkY a ESifh b aygif;í&aom tajzudk Arithmetic operators
addition (+) toHk;jyKí Assign jyKvkyfygonf/
(C) a ESifh b aygif;í &aomtajz sum udk uGefysLwm Screen wGif Output
data tjzpfjyo&ef printf function udk toHk;jyKxm;ygonf/
txufyg Exercise 1 program udk Run ygu Program onf tvdt
k avQmuf
tvkyv
f yk af qmifomG ;rnf/ &&Sv
d mrnf tajzudk Munfv
h v
kd Qif Alt + F5 udk ESyd yf gu uGeyf sLwm
Screen wGif The sum of the given two number is 11 [k jyoay;ygrnf/
Example 2.11
40/ /* Example 2.11 The sum of two number */
#include<stdio.h>
main()
{ int a,b,sum; /*Variable Declaration */
printf(“\nEnter two integer number > “);
scanf(“%d %d”,&a,&b);
sum = a + b;
printf(“The sum of two number is %d.\n”);
}

txufyg Exercise 2 program udk avhvmrnfqdkygu
(u) a, b ESihf sum variable name udk Data type int tjzpfaMujimay;jcif;jzpf
ygonf/
(c ) printf function udk toHk;jyKNyD; Enter Number qdkonfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/

Contents

TurboC

(*)
(C)
(C)

22

uuuGef

scanf function udk toH;k jyKNy;D Keyboard rS½u
dk x
f nfrh nfh a ESihf b wefz;kd udk

vufc&H eftwGujf zpfygonf/
sum xJodkY a ESifh b aygif;í&aom tajzudk Arithmetic operators
addition (+) toHk;jyKí Assign jyKvkyfygonf/
a ESifh b aygif;í &aomtajz sum udk uGefysLwm Screen wGif Output
data tjzpfjyo&ef printf function udk toHk;jyKxm;ygonf/

txufyg Program udk Run rnfqdkygu uGefysLwm Screen wGif Enter two
integer number [k Data udk Keyboard ½dkufxnfhay;&ef today;aom pmaMumif;
ay:vmrnf/ xdktcg Keyboard rS integer num ESpfckudk ½dkufxnfhNyD; Enter key udk
ESyd yf g/ Oyrm- integer number 6 ESihf 5 udk ½du
k x
f nfí
h Enter key udEk ydS yf gu program
Run oGm;ygrnf/ Alt + F5 udk ESdyfygu uGefysLwm Screen wGif The sum of two
number is 11 [k jyoay;ygrnf/
rSwcf su/f
scanf function udk toH;k jyKaomtcg Output format wGif comma (,)
udk toHk;jyKygu Keyboard rS data ½dkufxnfhaomtcg comma(,) cHí
½dkufxnfhay;&rnf/ Oyrm- Output format wGif scanf ("%d,%d",
&a,&b) [k owfrw
S af y;ygu Data xnfah omtcg 6,5 [k ½du
k x
f nfNh y;D
Enter udkESdyf&ygrnf/
Example 2.12
41/ /* Exercise 3 This program convert fahrenheit to centigrade. */
#include<stdio.h>
main()
{
float fah,cent; /*Variable Declaration */
printf(“\nEnter the Fahrenheit degree > “);
scanf(“%f”,&fah);
cent = 5.0/9 * (fah -32);
printf(“Equivalent Centigrade =%.2f\n”,cent);
}

Contents

TurboC

23

uuuGef

txufyg Example 2.12 program udk avhvmrnfqdkygu
(u) fah ESihf cent variable name udk Data type float tjzpfaMujimay;jcif;jzpf
ygonf/
(c ) printf function udk toH;k jyKNy;D Enter the Fahrenheit degree > qdo
k nfh
today; pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
(*) scanf function udk toH;k jyKNy;D Keyboard rS½u
dk x
f nfrh nfh fah wefz;kd udk
vufc&H eftwGujf zpfygonf/
(C) cent xJodkY Fahrenheit rS Centigrade odkY ajymif;aom yHkaoenf;udk
tajzudk Arithmetic operators rsm;toH;k jyKí Assign jyKvyk yf gonf/
(C) &&Sv
d maom Centigrade wefz;kd udk uGeyf sLwm Screen wGif Output data
'ór ESpaf e&m tjzpfjyo&ef printf function udk toH;k jyKxm;ygonf/
txufyg Program udk Run rnfqdkygu uGefysLwm Screen wGif Enter the
Fahrenheit degree > [k Data udk Keyboard ½du
k x
f nfah y;&ef today;aom pmaMumif;
ay:vmrnf/ xdktcg Keyboard rS Fahrenheit degree wpffckudk ½dkufxnfhNyD; Enter
key udk ESdyfyg/ Oyrm- Fahrenheit degree 100 udk ½dkufxnfhí Enter key udkESdyfygu
program Run oGm;ygrnf/ Alt + F5 udk ESdyfygu uGefysLwm Screen wGif Equivalent
Centigrade = 37.78 [k jyoay;ygrnf/
Example 2.13
42/ /* Exercise 2.13 Using Increment and Decerment Operators*/
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,sum;
a = b = 4;
sum = a + b; printf(“ a=%d b=%d Sum=%d\n”,a,b,sum);
sum = a ++ +b; printf(“ a=%d b=%d Sum=%d\n”,a,b,sum);
sum = ++a + b; printf(“ a=%d b=%d Sum=%d\n”,a,b,sum);
sum = - -a + b; printf(“ a=%d b=%d Sum=%d\n”,a,b,sum);

Contents

TurboC

24

uuuGef

sum = a - - + b; printf(“ a=%d b=%d Sum=%d\n”,a,b,sum);
getch();
}

txufyg Example 2.13 program udk avhvmrnfqdkygu
(u) a, b ESihf sum variable name udk Data type int tjzpfaMujimay;jcif;jzpf
ygonf/
(c ) a ESihf b xJoYkd integer constants number 4 udk Assign jyKvyk af y;onf/
(* ) sum xJoYkd a ESihf b aygif;ítajz&&S&d ef Arithmetic operators addition
(+) toHk;jyKí Assign jyKvkyfNyD; Output data jyay;jcif;jzpfygonf/
(C) sum xJoYkd a ESihf b aygif;ítajz&&S&d ef Arithmetic operators addition
(+) toH;k jyKí Assign jyKvy
k Nf y;D a \wefz;kd udw
k pfcw
k ;kd ap&ef Increment
operator toH;k jyKí Output data jyay;jcif;jzpfygonf/
(i ) a \wefz;kd udw
k pfcw
k ;kd ap&ef Increment operator toH;k jyKí sum xJoYkd
a ESifh b aygif;ítajz&&Sd&ef Arithmetic operators addition (+)
toHk;jyKí Assign jyKvkyfNyD; Output data jyay;jcif;jzpfygonf/
(p ) a \wefzdk;udkwpfckavsmhap&ef Decrement operator toHk;jyKí sum
xJodkY a ESifh b aygif;ítajz&&Sd&ef Arithmetic operators addition
(+) toHk;jyKí Assign jyKvkyfNyD; Output data jyay;jcif;jzpfygonf/
(q) sum xJoYkd a ESihf b aygif;ítajz&&S&d efArithmetic operators addition
(+) toHk;jyKí Assign jyKvkyfNyD; a \wefzdk;udkwpfckavsmhap&ef
Decerment operator toHk;jyKí Output data jyay;jcif;jzpfygonf/
(Z ) &&Sdvmrnftajzrsm;udk uGefysLwm Screen udkwGif az:jyay;&eftwGuf
gets function udk toHk;jyKygonf/
txufyg Example 2.13 program udk Run ygu Program onf tvdk
tavQmuf tvkyv
f yk af qmifomG ;Ny;D uGeyf sLwm Screen wGif atmufygtwdik ;f az:jyay;
ygrnf/
a = 4 b = 4 Sum = 8
a = 5 b = 4 Sum = 8 ( a ESifh b udk aygif;NyD;rS a wefzdk;udkwpfckwdk; )
a = 6 b = 4 Sum = 10 (a wefzdk;udk wpfckwdk;NyD;rS a ESifh b udk aygif; )

Contents

TurboC

25

uuuGef

a = 5 b = 4 Sum = 9 (a wefzdk;udk wpfckavsmhNyD;rS a ESifh b udk aygif;)
a = 4 b = 4 Sum = 9 ( a ESifh b udk aygif;NyD;rS a wefzdk;udkwpfckavsmh)
Example 2.14
43/ #include<stdio.h>
main()
{
int dividend, divisor, answer, remainder;
printf(“Enter two number = “);
scanf(“%d %d”,&dividend,&divisor);
answer = dividend / divisor;
remainder = dividend % divisor;
printf(“\n%d / %d = %d Remainder %d\n”,
dividend,divisor,answer,remainder);
}

txufyg Example 2.14 program udk avhvmrnfqdkygu
(u) dividend, divisor,answer ESifh remainder variable name udk Data
type int tjzpfaMujimay;jcif;jzpfygonf/
(c ) printf function udk toHk;jyKNyD; Enter two number qdkonfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
(*) scanf function udk toHk;jyKNyD; Keyboard rS½kdufxnfhrnfh dividend
and divisor number wefz;kd udk vufc&
H eftwGujf zpfygonf/
(C) answer xJoYkd dividend udk divisor jzifph m;ítajz&&S&d ef Arithmetic
operators addition (/) toHk;jyKí Assign jyKvkyfygonf/
(i ) remainder xJodkY dividend udk divisor jzifhpm;í &&Sdrnfht<uif;udk
Arithmetic operators addition (%) toH;k jyKí Assign jyKvy
k yf gonf/
(p ) uGeyf sLwm Screen wGif Output data tjzpfjyo&ef printf function udk
toH;k jyKxm;ygonf/

Contents

TurboC

26

uuuGef

txufyg Program udk Run rnfqdkygu uGefysLwm Screen wGif Enter two
number [k Data udk Keyboard ½du
k x
f nfah y;&ef today;aom pmaMumif; ay:vmrnf/
xdt
k cg Keyboard rS dividend ESihf divisor number ESpcf u
k kd ½du
k x
f nfNh y;D Enter key udk
ESyd yf g/ Oyrm- 10 ESihf 3 udk ½du
k x
f nfí
h Enter key udEk ydS yf gu program Run oGm;ygrnf/
Alt + F5 udk ESy
d yf gu uGeyf sLwm Screen wGif 10 / 3 = 3 Remainder 1 [k jyoay;ygrnf/

Contents

TurboC

27

uuuGef

tcef;(3)
CONTROL STATEMENTS
if Statement
44/ if Statement qdkonfrSm Preogram wGif a&;om;xm;aom condition trSm;
trSefudk pDppfay;aom Conditional statement wpfckjzpfygonf/ condition rSefygu
statement udk ajz&Sif;ay;NyD; condition rSm;ygu statement udk rajz&Sif;yJ aemufwpf
aMumif;odYk qif;oGm;ygrnf/ if statement wGif statement wpfcx
k ufyykd gu curly bracket
{ jzifh pay;&NyD; } jzifh ydwfay;&rnf/ condition ESpfckjzpfcJhygu if else statement udk
toHk;jyKNyD;? condition ESpfckxuf ydkygu else if statement udk toHk;jyKygonf/ if
Statement \ a&;xHk;yHkponf atmufygtwdkif;jzpfonfif statement
if (condition) true statement;
else false statement;
Example 3.1
45/ /* Example Using If Statement */
#include<stdio.h>
main( )
{
int mark;
printf("Enter subject marks > ");
scanf("%d",&mark);
if (mark>49) printf("Pass");
if (mark < 50 ) printf("Fail");
}

txufyg Example 3.1 program udk avhvmrnfqdkygu
(u) mark udk variable type int tjzpfaMujimay;ygonf/
(c ) printf function udk toH;k jyKNy;D Enter subject mark > qdo
k nfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
(* ) scanf function udk toHk;jyKNyD; Keyboard rS½kdufxnfhrnfh mark udk

Contents

28

TurboC

(C)

uuuGef

vufc&H eftwGujf zpfygonf/
if statement udk toHk;jyKí mark onf 49 ausmf rSefygu Pass [k
Output udk jyay;&efjzpfNyDd;? 50 xuf i,fygu Fail [k jyoay;&efjzpf
ygonf/

txufyg Program udk Ctrl ESifh F9 key udkESdyfí Run rnfqdkygu uGefysLwm
Screen wGif Enter subject mark > [k Data udk Keyboard rS½dkufxnfhay;&ef tod
ay;aom pmaMumif;ay:vmrnf/ xdt
k cg Keyboard rS bmom&yftrSwu
f kd ½du
k x
f nfNh y;D
Enter key udk ESdyfyg/ Oyrm- 56 udk ½dkufxnfhí Enter key udkESdyfygu program Run
oGm;ygrnf/ if (mark > 49) udkawGUaomtcg mark onf 49 xufausmfonfjzpfojzifh
condition rSefojzifh printf("Pass") statement udk jyKvkyfoGm;NyD;? if (mark <50)
statement odkYqif;oGm;ygonf/ mark onf 50 xufi,faomaMumifh condition
rSm;aeojzifh ¤if; statement udk vkyfaqmifrIrjyKvkyfbJ atmufwpfMumif;odkY qif;oGm;
ygrnf/ } udak wGaY omtcg Program rS xGuo
f mG ;ygonf/ Alt + F5 udk ESyd yf gu uGeyf sLwm
Screen wGif Pass [k jyoay;ygrnf/ tu,fí 40 udk ½du
k x
f nfí
h Enter key udEk ydS yf gu
program Run oGm;ygrnf/ if ( mark > 49) udkawGUaomtcg mark onf 49 xuf
i,faomaMumifh condition rSm;aeojzifh ¤if; statement udk vkyfaqmifrI rjyKvkyfbJ
atmufwpfaMumif;odkY qif;oGm;NyD; if (mark < 50) condition udkawGUaomtcg
condition rS e f a eojzif h printf("Fail") statement ud k vk y f a qmif o G m ;ygNyD ;
atmufwpfaMumif;odYk qif;oGm;Ny;D } udak wGUaomtcg program rSxu
G o
f mG ;ygonf/ Alt
+ F5 udk ESdyfygu uGefysLwm Screen wGif Fail [k jyoay;ygrnf/
Example 3.2
46/ #include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int num;
printf(“Enter number = \n “);
scanf(“%d”,&num);
if (num < 0)

Contents

TurboC

29

uuuGef

printf(“\nNegative number”);
if (num > 0)
printf(“\nPositive number”);
if (num= =0)
printf(“\nZero number”);
}

txufyg program udk Run vdkufygu(u) clrscr function aMumifh monitor screen udk yxrOD;pGm clear vkyfyg
onf/
( c) num udk integer variable tjzpfaMunmay;ygonf/
( *) screen wGif Enter number = pmaMumif;ESifhtwl data udkvufcH&ef
cursor udk ay:apygonf/
(C) keyboard rS *Pef;wpfckckudk½dkufxnfhay;&ygrnf/ Oyrm 5 *Pef;udk
½dkufxnfhNyD; Enter key udk ESdyfyg/ xdktcg num onf 5 jzpfoGm;ygonf/
( i) yxrOD;pGm if statement wGif num onf 0 (zero) xuf i,fovm;
ppfygonf/ num onf 5 jzpfojzifh 0 (zero) xuf ri,faomaMumifh
atmuf wpfaMumif;odkY qif;oGm;ygonf/
( p) 'kwd, if statement wGif num onf 0 (zero) xuf BuD;ovm;
ppfygonf/ num onf 0(zero) xufBu;D aomaMumifh printf("\nPositive
number") statement udk jyKvy
k o
f mG ;Ny;D screen wGif Positive number
[kjyNyD; atmufpmaMumif;odkYqif;oGm;ygrnf/
(q) wwd, if statement wGif num onf 0(zero) ESifhnDovm;ppfygonf/
num onf 0(zero) ESir
hf nDaomaMumifh ¤if; statement udk rjyKvyk af wmhyJ
close bracket odkY qif;oGm;NyD; program onf &yfoGm;ygrnf/
Example 3.3
47/ #include<stdio.h>
#include<conio.h>
main()
{
clrscr();

Contents

TurboC

30

uuuGef

int sub1,sub2,sub3,sub4;
printf(“\nEnter marks of four subject “);
scanf(“%d%d%d%d”,&sub1,&sub2,&sub3,&sub4);
if ((sub1<50) || (sub2<50) || (sub3<50) || (sub4<50))
printf(“\nFailed”);
else printf(“\Passed”);
}

txufyg program udk Run vdkufygu(u) screen wGif Enter marks of four subject pmaMumif;ESifhtwl data
udkvufcH&ef cursor udk ay:apygonf/
( c) keyboard rS bmom&yfav;ck\ trSwrf sm;ud½k u
kd x
f nfah y;&ygrnf/ Oyrm
56 85 65 70 trSwfrsm;udk ½dkufxnfhNyD; Enter key udk ESdyfyg/ xdktcg
sub1 wGif 56 sub2 wGif 85 sub3 wGif 65 sub4 wGif 70 toD;oD;jzpf
oGm;ygonf/
( *) yxrOD;pGm if statement wGif sub1, sub2, sub3, sub4 tm;vH;k wdo
Yk nf
50 xuf i,fovm; ppfygonf/ bmom&yfav;ckv;kH \ trSwr
f sm;onf
50 xuf ri,faomaMumifh printf("\nFailed") statement udk tjyKvy
k yf J
else printf("\nPassed") statement udkjyKvkyfoGm;ygonf/ xdkYaemuf
close bracket odkY qif;oGm;NyD; program onf &yfoGm;ygrnf/
(C) Alt + F5 udk ESdyfygu screen wGif Passed [k jyay;ygrnf/ tu,fí
bmom&yftrSwaf v;ckukd ½du
k x
f nf&h mwGif 45 51 55 80 [k ½du
k x
f nfyh gu
bmom&yf av;ckwiG f wpfbmomonf 50 xuf i,faomaMumifh Failed
[k jyay;ygrnf/
Example 3.4
48/ /* Example Using If else Statement */
#include<stdio.h>
main( )
{
int sub1,sub2;
printf("Enter two subject marks > ");

Contents

TurboC

31

uuuGef

scanf("%d %d",&sub1,sub2);
if (sub1>49 && sub2>49) printf("Pass");
else printf("Fail");
}

txufyg Example program udk avhvmrnfqdkygu
(u) sub1 ESifh sub2 udk variable type int tjzpfaMujimay;ygonf/
(c ) printf function udk toH;k jyKNy;D Enter two subject > qdo
k nfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
(* ) scanf function udk toHk;jyKNyD; Keyboard rS½kdufxnfhrnfh sub1, sub2
udk vufcH&eftwGufjzpfygonf/
(C) if statement udk toHk;jyKí sub1 ESifh sub2 ESpfbmomvHk; 49 ausmf
rSefygu Output udk Pass [kjyay;yg/ rSm;ygu Fail [k jyay;yg/
txufyg Program udk Run rnfqdkygu uGefysLwm Screen wGif Enter two
subject mark > [k Data udk Keyboard ½dkufxnfhay;&ef today;aompmaMumif;
ay:vmrnf/ xdt
k cg Keyboard rS bmom&yftrSwEf pS cf u
k kd ½du
k x
f nfNh y;D Enter key udk
ESdyfyg/ Oyrm- 55 66 udk ½dkufxnfhí Enter key udkESdyfygu program Run oGm;ygrnf/
if (sub1>49 || sub2>49) condition udkawGUaomtcg bmom&yftrSwfESpfckvHk;onf
49 xuf MuD;aeaom condition rSefaeaomaMumifh printf("Pass") statement udk
jyKvyk o
f mG ;Ny;dD else printf("Fail") statemtent udk ausmo
f mG ;Ny;dD } odq
Yk if;oGm;Ny;D program
rSxu
G o
f mG ;ygrnf/ Alt + F5 udk ESyd yf gu uGeyf sLwm Screen wGif Pass [k jyoay;ygrnf/
tu,fí 55 45 udk ½dkufxnfhí Enter key udkESdyfygu program Run oGm;ygrnf/ if
(sub1>49 || sub2>49) condition udkawGUaomtcg sub1 onf 49 xufBuD;NyD; sub2
onf 49 xufi,faomaMumifh bmom&yfESpfckvHk;onf 49 xuf BuD;aom condition
rSm;aeaomaMumifh printf("Pass") statement udk rjyKvkyfbJ else printf("Fail")
statemtent odq
Yk if;oGm;Ny;D printf("Fail") statement udk jyKvyk Nf y;D atmufwpfaMumif;odYk
qif;oGm;Ny;D } awGUaomtcg program rSxu
G o
f mG ;ygrnf/ Alt + F5 udk ESyd yf gu uGeyf sLwm
Screen wGif Fail [k jyoay;ygrnf/

Contents

TurboC

32

uuuGef

Example 3.5
49/ #include<stdio.h>
main()
{
int num;
printf(“\nEnter number > “);
scanf(“%d”,&num);
if (num > 0)
printf(“\nPositive number ”);
if (num < 0)
printf(“\nNegative number”);
if (num==0)
printf(“\nZero number”);
}

txufyg Example program udk avhvmrnfqdkygu
(u) num udk variable type int tjzpfaMujimay;ygonf/
(c ) printf function udk toHk;jyKNyD; Enter number > qdkonfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
(* ) scanf function udk toHk;jyKNyD; Keyboard rS½kdufxnfhrnfh num udk
vufc&H eftwGujf zpfygonf/
(C) if statement udk toH;k jyKí num onf 0 xufBu;D ygu Positive [k¤if;
0 xufi,fygu Negative [k¤if;? 0 ESin
hf yD gu Zero [k Output screen
wGif jyay;&efjzpfygonf/
txufyg Program udk Run rnfqdkygu
(u) uGefysLwm Screen wGif Enter number> [k Data udk Keyboard
½dkufxnfhay;&ef today;aompmaMumif; ay:vmrnf/
( c) xdktcg Keyboard rS number wpfckckudk ½dkufxnfhNyD; Enter key udk
ESdyfyg/ Oyrm- 5 udk ½dkufxnfhí Enter key udkESdyfygu program Run
oGm;ygrnf/
( *) if (num>0) condition udkawGUaom tcg num onf 0 xufBuD;aom
aMumifh condition rSefaeojzifh printf("Positive") statement udk

Contents

TurboC

(C)

( i)

( p)

33

uuuGef

jyKvkyfoGm;NyDd; atmufwpfaMumif;qif;oGm;ygonf/
if(num<0) statement udk qif;Ny;D num onf 0 xufi,fovm; ppfaq;
ygonf num onf 0 xufBuD;aomaMumifh condition rSm;ojzifh
printf("Negative") statemtent udk ausmo
f mG ;Ny;dD atmufwpfaMumif;odYk
qif;oGm;ygonf/
if(num= =0) odkY qif;NyD; num onf 0 ESifhnDrnDppfygonf num onf
0 ES i f h r nD o jzif h condition rS m ;aomaMumif h printf("Zero")
udkausmfoGm;NyD; } odkYqif;oGm;NyD; program rSxGufoGm; ygrnf/
Alt + F5 udk ESdyfygu uGefysLwm Screen wGif Positive number [k
jyoay;ygrnf/ tu,fí -2 udk ½dkufxnfhí Enter key udkESdyfygu
program Run oGm;ygrnf/ if (num>0) condition udkawGUaom tcg
num onf 0 xuf i ,f a omaMumif h condition rS m ;aeojzif h
printf("Positive") statement udk ausmfoGm;NyDd; atmufwpfaMumif;
if(num<0) statement ud k q if ; NyD ;
num onf
0
xufi,fovm;ppfaq;ygonf num onf 0 xufi,faomaMumifh
condition rSeo
f jzifh printf("Negative") statemtent udk jyKvyk o
f mG ;í
if(num= =0) odkY qif;NyD; num onf 0 ESifhnDrnDppfygonf num onf
0 ES i f h r nD o jzif h condition rS m ;aomaMumif h printf("Zero")
udkausmfoGm;NyD; } odkYqif;oGm;NyD; program rSxGufoGm;ygrnf/ Alt + F5
udk ESyd yf gu uGeyf sLwm Screen wGif Negative number [k jyoay;ygrnf/
tu,fí 0 udk ½dkufxnfhí Enter key udkESdyfygu program Run
oGm;ygrnf/ if (num>0) condition udkawGUaom tcg num onf 0
xufrBuD;ojzifh condition rSm;aeaomaMumifh printf("Positive")
statement udk ausmo
f mG ;í atmufwpf aMumif; if(num<0) statement
udkqif;NyD; num onf 0 xufi,fovm; ppfaq;ygonf num onf 0
xufri,faomaMumifh condition rSm;ojzifh printf("Negative")
statemtent udk ausmfoGm;í if(num= =0) odkY qif;NyD; num onf 0
ESin
hf rD nDppfygonf num onf 0 ESin
hf o
D jzifh condition rSeaf omaMumifh
printf("Zero") udjk yKomG ;í } odq
Yk if;oGm;Ny;D program rSxu
G o
f mG ; ygrnf/
Alt + F5 udk ESdyfygu uGefysLwm Screen wGif Zero number [k

Contents

34

TurboC

uuuGef

jyoay;ygrnf/
Example 3.6
50/ #include<stdio.h>
main()
{
int num;
printf(“\nEnter number “);
scanf(“%d”,&num);
if (num > 0)
printf(“\nPositive number”);
else if(num < 0)
printf(“\nNegative number”);
else if (num==0)
printf(“\nZero number”);
}

txufyg Example program udk avhvmygu
(u) num udk variable type int tjzpfaMujimay;ygonf/
(c ) printf function udk toHk;jyKNyD; Enter number > qdkonfh today;
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
(* ) scanf function udk toHk;jyKNyD; Keyboard rS½kdufxnfhrnfh num udk
vufc&H eftwGujf zpfygonf/
(C) if statement udk toH;k jyKí num onf 0 xufBu;D ygu Positive [k¤if;
0 xufi,fygu Negative [k¤if;? 0 ESin
hf yD gu Zero [k Output screen
wGif jyay;&efjzpfygonf/
txufyg Program udk Run rnfqdkygu
(u) uGefysLwm Screen wGif Enter number> [k Data udk Keyboard
½dkufxnfhay;&ef today;aompmaMumif; ay:vmrnf/
( c) xdktcg Keyboard rS number wpfckckudk ½dkufxnfhNyD; Enter key udk
ESdyfyg/ Oyrm- 5 udk ½dkufxnfhí Enter key udkESdyfygu program Run
oGm;ygrnf/

Contents

TurboC

( *)

35

uuuGef

if (num>0) condition udkawGUaom tcg num onf 0 xufBuD;aom
aMumifh condition rSefaeojzifh printf("Positive") statement udk
jyKvkyfoGm;NyDd; else if(num<0) statement ESifh else if(num= =0)
statement udk ausmo
f mG ;í } odq
Yk if;oGm;Ny;D program rSxu
G o
f mG ; ygrnf/
Alt + F5 udk ESdyfygu uGefysLwm Screen wGif Positive number [k
jyoay;ygrnf/ tu,fí -2 udk ½dkufxnfhí Enter key udkESdyfygu
program Run oGm;ygrnf/ if (num>0) condition udkawGUaom tcg
num onf 0 xuf i ,f a omaMumif h condition rS m ;aeojzif h
printf("Positive") statement udk ausmo
f mG ;í atmufwpfaMumif; else
if(num<0) statement udkqif;NyD; num onf 0 xufi,fovm;
ppfaq;ygonf num onf 0 xufi,faomaMumifh condition rSeo
f jzifh
printf("Negative") statemtent udk jyKvkyfoGm;í else if(num= =0)
udk ausmo
f mG ;Ny;D } odq
Yk if;oGm;Ny;D program rSxu
G o
f mG ;ygrnf/ Alt + F5
udk ESyd yf gu uGeyf sLwm Screen wGif Negative number [k jyoay;ygrnf/
tu,fí 0 udk ½dkufxnfhí Enter key udkESdyfygu program Run
oGm;ygrnf/ if (num>0) condition udkawGUaom tcg num onf 0
xufrBuD;ojzifh condition rSm;aeaomaMumifh printf("Positive")
statement udk ausmfoGm;í atmufwpf aMumif; else if(num<0)
statement udkqif;NyD; num onf 0 xufi,fovm; ppfaq;ygonf
num onf 0 xufri,faomaMumifh condition rSm;ojzifh printf
("Negative") statemtent udk ausmo
f mG ;í else if(num= =0) odYk qif;Ny;D
num onf 0 ESifhnDrnDppfygonf num onf 0 ESifhnDojzifh condition
rSefaomaMumifh printf("Zero") udkjyKvkyfí } odkYqif;oGm;NyD; program
rSxGufoGm;ygrnf/ Alt + F5 udk ESdyfygu uGefysLwm Screen wGif Zero
number [k jyoay;ygrnf/

goto Statement
51/ Program wpfck\ yHkrSefvrf;aMumif;rS tjcm;wpfaeodkY oGm;vdkygu goto statement udktoHk;jyK&ygonf/ goto statement udk toHk;jyKaomtcg oGm;vdkaomae&mudk
variable name az:jyay;&ygrnf/ Varible name udk colon(:) ESiw
hf NJG y;D a&;ay;&ygonf/

Contents

TurboC

36

uuuGef

Example 3.7
52/ #include<stdio.h>
main()
{
long int first,last, odds,sum=0;
printf(“\nEnter first and last number >”);
scanf(“%ld %ld”,&first,&last);
if (first % 2 !=0) odds= first;
if (first % 2 ==0) odds=first+1;
again:
if (odds <=last)
{
sum =sum + odds;
odds = odds +2;
goto again;
}
printf(“Sum of odd number %ld though %ld = %ld\n”,first,last,sum);
}

txufyg program onf rdrd½dkufxnfhaom yxr*Pef;ESifh aemufqHk;*Pef;
twGi;f &Sd r*Pef;rsm;tm;vH;k \aygif;v'fukd goto statement udk toH;k jyK&mS aom program
jzpfygonf/
txufyg Example3.6 program udk avhvmrnfqdkygu
(u) first, last, odds, sum wd k Y u d k variable type long int
tjzpfaMujimay; ygonf/
(c ) printf function udk toH;k jyKNy;D Enter first and lasr number>
qdkonfh today;pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
(* ) scanf function udk toH;k jyKNy;D Keyboard rS½u
dk x
f nfrh nfh first
and last udk vufcH&eftwGufjzpfygonf/
(C) if statement udk toHk;jyKí first udk 2 jzifhpm;ít<uif;onf 0
ESifh rnDvQif odds xJudk first udkxnfhyg/ first udk 2 jzifhpm;í
t<uif;onf 0 ESin
hf yD gu odds xJoYkd first udk 1 aygif;íxnfyh g/

Contents

TurboC

37

uuuGef

txufyg Program udk Run rnfqdkygu
(u) uGefysLwm Screen wGif Enter first and last number > [k
Data udk Keyboard ½dkufxnfhay;&ef today;aompmaMumif;
ay:vmrnf/ xdktcg Keyboard rS *Pef;ESpfckudk spacebar
cHí ½du
k x
f nfNh y;D Enter key udk ESyd yf g/ (Oyrm- 1 10 udk ½du
k x
f nfh
í Enter key udkESdyfygu program Run oGm;ygrnf/ xdktcg
first = 1 ESifh last = 10 jzpfoGm;ygonf/)
(c) if (first % 2 !=0) condition udak wGUaomtcg 1 udk 2 jzifph m;í
t<uif;onf 0 ESifhrnDaomaMumifh odds xJodkY first number
1 udkxnfhay;ygonf/ odds= 1 jzpfoGm;onf/
(*) atmufwpfaMumif; if(fisrt %2 = = 0) udkawGUaomtcg 1 udk
2 jzifh pm;í t<uif;onf 0 ESihf rnDaomaMumifh ¤if; statement
udk vkyfaqmifrIrjyKvkyfbJ if(odds<=last) statement udk
qif;oGm;ygonf/
(C) odds onf last xuf i,fonf(odkYr[kwf) nDaevQifí ¤if;
atmufrS statement rsm;udk vkyfaqmif&efjzpfygonf/
( i) odds onf 1 jzpfaomaMumifh last xufi,faomaMumifh sum
xJudk odds 1 udkaygif;xnfhygonf/ sum = 1 jzpfoGm;ygonf/
( p) odds xJudk 2 aygif;xnfhygonf/ odds = 3 jzpfoGm;ygonf/
(q) goto again udk awGUaomtcg again udkjyefoGm;NyD; odds ESifh
last udk EIi
d ;f ,SOyf gonf/ odds onf last xuf i,fae (odrYk [kw)f
nDaeoí if (odds<=last) atmufu statement rsm;udk xyfcg
wvJ jyKvkyfoGm;ygrnf/
(Z ) tcsdefwGif odds onf 11 jzpfoGm;ygonf/ xdktcg odds onf
last xuf BuD;aomaMumifh atmufu statement rsm;ud k
jyKvyk jf cif;r&Sb
d J ausmo
f mG ;Ny;D Sum of odds numbers 1 through
10 = 25 qdak omtajzudk ½du
k jf yNy;D program onf &yfomG ;ygrnf/
switch Statement
53/ Program wpfcw
k iG f Statement rsm;yg0ifaom variable group tkypf rk S oGm;vdk
aom statement qDodkY oGm;vdkygu switch statement udktoHk;jyK&ygonf/

Contents

TurboC

38

uuuGef

Example 3.8
54/ /*Vowel count*/
#include<stdio.h>
#include<ctype.h>
void main()
{
char st[81];
int i,count;
puts(“Enter a Sentence”);
gets(st);
for (i=count=0;st[i];i++)
switch (toupper(st[i]))
{
case ‘A’:
case ‘E’:
case ‘I’:
case ‘O’:
case ‘U’:
count++;
}
printf(“\nYour Sentence is %d vowel.”,count);
}

txufyg Program onf Sentence wpfaMumif;wGif yg0ifaom vowel ta&
twGufudk a&wGufcdkif;aom prograam wpfyk'fjzpfygonf/
Example 3.7 program udk Run rnfqy
kd gu
(u) uGefysLwm Screen wGif Enter a Sentence [k Data udk Keyboard

(c)

½d k u f x nf h a y;&ef tod a y;aompmaMumif ; ay:vmrnf / xd k t cg
Keyboard rS Sentence wpfaMumif;udk ½du
k x
f nfNh y;D Enter key udk ESyd yf g/
Oyrm- Defcence Service Computer Department udk ½dkufxnfhí
Enter key udE
k ydS yf gu program Run oGm;ygrnf/
Keyboard rS Alt ESifh F5 udk wGJíESdyfygu Computer Screen wGif
Your Sentence is 12 vowel. [kjyay;ygrnf/

Contents

39

TurboC

uuuGef

for Statement
55/ Turbo C program wpfcw
k iG f xyfcgxyfcg Looping jyKvyk &f eftwGuf for statement udk toHk;jyKEdkifygonf/
for (exp1;exp2;exp3) statement(s);
Example 3.9
56/ #include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int i,j;
for (i=1;i<13;i++)
{
for (j=1;j<6;j++)
printf(“%2dx%2d=%3d “,j,i,i*j);
printf(“\n”);
}
}

txufygonf for looping udk toHk;jyKNyD; 1 rS 5 txd tvDZ,m; a&;om;xm
aom program wpfckjzpfygonf/
txufyg program udk Run vdkufygu atmufygtwdkif; 1 rS 5 txd tvD
Z,m;ud&k &Syd grnf/
1x
1x
1x
1x
1x
1x
1x

1= 1
2= 2
3= 3
4= 4
5= 5
6= 6
7= 7

2x
2x
2x
2x
2x
2x
2x

1=2
2=4
3=6
4=8
5 =10
6 =12
7 =14

3x
3x
3x
3x
3x
3x
3x

1=3
2=6
3=9
4 =12
5 =15
6 =18
7 =21

4x
4x
4x
4x
4x
4x
4x

1=4
2=8
3 =12
4 =16
5 =20
6 =24
7 =28

5x
5x
5x
5x
5x
5x
5x

1= 5
2 =10
3 =15
4 =20
5 =25
6 =30
7 =35

Contents

40

TurboC
1x 8= 8
1x 9= 9
1 x 10 =10
1 x 11 =11
1 x 12 =12

2 x 8 =16
2 x 9 =17
2 x 10 =20
2 x 11 =22
2 x 12 =24

3 x 8 =24
3 x 9 =27
3 x 10 =30
3 x 11 =33
3 x 12 =36

uuuGef
4 x 8 =32
4 x 9 =36
4 x 10 =40
4 x 11 =44
4 x 12 =48

5 x 8 =40
5 x 9 =45
5 x 10 =50
5 x 11 =55
5 x 12 =60

txufyg program avhvmygu(u) i, j udk int data type tjzpfaMujimay;ygonf/
( c) Screen udk clear vkyfygonf/
( *) for looping udk toHk;jyKí i wefbdk;udk 1 rS 12 txd looping udk
ygwfcikd ;f ygonf/
(C) twGif; for looping udk toHk;jyKí j wefbdk; 1 rS 6 xufi,fonfhtxd
looping udk ygwfcdkif;ygonf/
( i) twGif; Lopping wGif yxrOD;pGm j \ wefbdk; 1 tajrmufvu©Pm x
i wefbdk; 1 nDrQjcif;vu©Pm = j wefbdk; 1 ESifh i wefbdk; 1 wdkY\
ajrmufv'f 1 udk ½dkufay;ygonf/ xdkYaemuf j \ wefbdk;udk 1 wdk;NyD; 6
xufi,fonfhtxd vkyfaqmifoGm;ygonf/
( p)
(q)

( Z)
( ps)
(n)

(#)

( 1 x 1 = 1 2 x 1=2 3 x 1=3 4 x 1 = 4 5 x 1 = 5)
printf("\n") aMumifh atmufwpfaMumif;odq
Yk if;oGm;ygonf/
xdkaemuf i \ wefbdk;udk wpfwdk;í j \ wefbdk; 1 tajrmufvu©Pm
x i wefbdk; 2 nDrQjcif;vu©Pm = j wefbdk; 1 ESifh i wefbdk; 2 wdkY\
ajrmufv'f 1 udk ½dkufay;ygonf/
( 1 x 2 = 2 2 x 2 = 4 3 x 2 = 6 4 x 2 = 8 5 x 2 =10)
printf("\n") aMumifh atmufwpfaMumif;odq
Yk if;oGm;ygonf/
þodkYjzifh i \ wefbdk;udk 13 xuf i,fonfhtxd tvDZ,m;udk

½dkufay;ygrnf/
i \ wefbdk; 13 jzpfaomtcg tjyif for looping \ statement onf
rSm;oGm;aomaMumifh for looping rS xGufoGm;NyDd; program \ } odkY
qif;oGm;ygonf/
} udkawGUaom program onfNYyD;qHk;oGm;ygonf/

Contents

TurboC

41

uuuGef

while Statement
57/ Program wGif Looping operation wpfcu
k kd xyfcgxyfcg looping jyKvyk v
f ykd gu
while statement udk toHk;jyK&ygonf/
while statement \yHkpH
while (condition)
statement;
while aemuf&Sd condition onf rSefuefrI&Sdaeoí atmufu Statement udk
xyfcgxyfcgjyKvyk o
f mG ;ygrnf/ condition rSm;rSom Looping rS xGuyf grnf/ Statement
onf wpfckxufydkygu { jzifh pNyD; } jzifhydwfay;&ygonf/
do while Statement
58/ program wpfcw
k iG f Looping udk vnfywfaomtcg Looping \ aemufq;kH usrS
ywfoifrh ywfoifh ppfaq;vdyk gu do while Statement udk toH;k jyK&ygonf/ do while
statement \ yHkpH
do
Statement;
while(codition);
do while statement udk toHk;jyKaomtcg looping wpfckudk ppcsif; looping
xJudk 0ifa&mufNyD; looping xJrS statement rsm;udk vkyfaqmifrsm;vkyfaqmifoGm;NyD;
while awGUaomtcgrSom while aemufuGif;xJu codition rSefrrSefppfaq;NyD; condition rSey
f gu looping udyk wfNy;D condition rSm;ygu looping udk ywfciG rhf jyKbJ wpfjcm;
statement odkYqif;oGm;ygrnf/
Function
59/ Function qdo
k nfrmS main Function uJo
h Ykd rdrb
d mom&yfwnfEikd Nf y;D wnfaqmuf
xm;aom self-contained program wpfcu
k kd qdv
k ykd gonf/ C program wGif tenf;qH;k
main function wpfckyf&Sdygonf/ Function rsm;udk toHk;jyKjcif;tm;jzifh program wGif
xyfcgxyfcg jyKvkyf&rnfh tvkyfrsm; program wpfaerS ra&;bJ function topfwpfck
wnfaqmufNyD; 4if; function udk oGm;vkyfapygonf/ 4if;tjyif data rsm;udk program

wpfae&mrSwpfaeodkY ydkY&eftwGuftoHk;jyKygonf/

Contents

42

TurboC

uuuGef

tcef;(4)
C Program avhusifhcef;rsm;
avhusifhcef;(1)
60/ atmufyg Program onf Keyboard rS ½du
k x
f nfah om character udk Computer
Screen wGifjyay;aom Program wpfyk'fjzpfygonf/ Oyrm A udk ½dkufxnfhygu You
type A [k jyay;ygrnf/ tu,fí A udk r½du
k b
f J Enter odrYk [kwf ? wpfcck u
k kd ½du
k x
f nfyh gu
Your pressed ENTER key. odkYr[kwf You pressed QUESTION MARK key [k
jyoay;ygrnf/
#include<stdio.h>
main()
{ char ch;
printf(“Enter a character : “);
ch = getchar();
if (ch==’\n’)
printf(“Your pressed ENTER key.\n”);
else if (ch==’\?’)
printf(“\You pressed QUESTION MARK key.\n”);
else
printf(“You type %c.”,ch);
}

avhusifhcef;(2)
61/ atmufyg Program onf Keyboard rS ½du
k x
f nfah om character udk Computer
Screen wGifjyay;aom Program wpfyk'fjzpfygonf/ Oyrm A udk ½dkufxnfhygu You
type A [k jyay;ygrnf/ tu,fí A udk r½dkufbJ Enter odkYr[kwf Spacebar wpfcc
k u
k kd
½du
k x
f nfyh gu Your pressed ENTER key. odrYk [kwf You pressed Spacebar key [k
jyoay;ygrnf/

Contents

43

TurboC

uuuGef

#include<stdio.h>
#include<conio.h>
main()
{
char ch;
printf(“Enter a character : “);
ch = getche();
if (ch==32)
printf(“Your pressed SPACEBAR.\n”);
else if (ch==13)
printf(“\You pressed ENTER key.\n”);
else
printf(“You type %c.\n”,ch);
}

avhusifhcef;(3)
62/ atmufyg Program onf switch Statement udk toHk;jyKí vkyftm;cudk
&SmazGaom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
main()
{
int clas;
float hour,wage,pay;
printf(“Enter class and hours worked\n”);
scanf(“%d,%f”,&clas,&hour);
switch (clas)
{

Contents

44

TurboC

uuuGef

case 1: wage=4.0; break;
case 2: wage=5.5; break;
case 3: wage=7.5; break;
case 4: wage=8.75; break;
default: puts(“Error! Plase enter new data.”);
goto EXIT;
}
if (hour >40) pay=40*wage+1.5*wage*(hour-40);
else pay=hour*wage;
printf(“Pay=%6.2f”,pay);
EXIT: printf(“\n”);
}

avhusifhcef;(4)
63/ atmufyg Program onf ypönf;wpfck\ item name, price ESifh unit udk
½dkufxnfhaom Amount udk&SmazGaom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
char name[80];
int units;
float price;
printf(“Enter item name, price, units, and amount\n”);
scanf(“%s%f%d”,name,&price,&units);
printf(“Name

Price Units Amount\n”);

Contents

45

TurboC
printf(“~~~~
printf(“%s

uuuGef

~~~~~ ~~~~~ ~~~~~~\n”);
%0.2f %5d 0.2f\n”,name,price,units,price*units);

}

avhusifhcef;(5)
64/ atmufyg Program onf Palindrome [kwf^r[kwf &SmazGaom Program
wpfy'k jf zpfygonf/
/*String Palindrome*/
#include<stdio.h>
#include<string.h>
#include<conio.h>
main()
{ clrscr();
char st1[81],st2[81];
puts(“Enter String”);
gets(st1);
strcpy(st2,st1);
if (strcmp(strrev(st1),st2))puts(“Not Palindrome”);
else puts(“Palindrome”);
}

avhusifhcef;(6)
65/ atmufyg Program onf Keyboard rS ½dkufxnfhaom *Pef; 2 ck twGif;&Sd
r*Pef;rsm;\ aygif;v'fudk &SmazGaom Program wpfyk'fjzpfygonf/
#include<stdio.h>
main()
{

Contents

46

TurboC

uuuGef

long int first,last, odds,sum=0;
printf(“\nEnter first and last >”);
scanf(“%ld %ld”,&first,&last);
if (first % 2 !=0) odds= first;
if (first % 2 ==0) odds=first+1;
again:
if (odds <=last)
{ sum =sum + odds;
odds = odds +2;
goto again;
}
printf(“Sum of odd number %ld though %ld = %ld\n”,first,last,sum);
}

avhusifhcef;(7)
66/ atmufyg Program onf Keyboard rS ½dkufxnfhaom String wpfck twGif;&Sd
rdrd&Smvdkonfh character ae&mudk &SmazGaom Program wpfyk'fjzpfygonf/
/*Position of Character*/
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
char string[20];
char *ptr,c=’r’;
strcpy(string,”This is a string”);

Contents

TurboC

47

uuuGef

ptr=strchr(string,c);
if (ptr) printf(“The character %c is at position %d\n”,c,
(ptr-string)+1);
else printf(“The character was not found\n”);
}

avhusifhcef;(8)
67/ atmufyg Program onf Keyboard rS ½dkufxnfhaom Main String wpfck
twGif;&Sd rdrd&Smvdkonfh character ae&mudk Substring wGif ½dkufxnfhNyD; o&SmazGaom
Program wpfyk'fjzpfygonf/
/*Position of Substring*/
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
char st1[81],st2[81],*ptr;
gotoxy(30,12);puts(“Enter Main String “);
gotoxy(48,12);gets(st1);
gotoxy(30,13);puts(“Enter Sub String\n “);
gotoxy(48,13);gets(st2);
gotoxy(30,14);ptr=strstr(st1,st2);
gotoxy(30,15);
if (ptr)
printf(“Fond at position %d”,ptr - st1);
else

Contents

48

TurboC

uuuGef

printf(“Not Found”);
getch();
}

avhusifhcef;(9)
68/ atmufyg Program onf Keyboard rS ½du
k x
f nfah om *Pef;rsm;udk ajymif;a&GUí
Sort jyKvkyf tpDtpOfwus jyoay;aom Program wpfyk'fjzpfygonf/
/*Pointer exchange sort*/
#include<stdio.h>
#include<conio.h>
void exchange(int *,int *);
void main()
{
clrscr();
int i,a[5],j;
for (i=0;i<5;i++)
{
printf(“\nEnter number “);
scanf(“%d”,&a[i]);
}
for (i=0;i<4;i++)
for (j=0;j<4-i;j++)
if (a[j]>a[j+1])
exchange(&a[j],&a[j+1]);
printf(“\nSorted order \n”);
for (i=0;i<5;i++)
printf(“%10d”,a[i]);

Contents

TurboC

49

uuuGef

}
void exchange(int *x,int *y)
{
int t;
t=*x,*x=*y,*y=t;
}

avhusifhcef;(10)
69/ atmuf y g Program onf Keyboard rS ½d k u f x nf h a om Sentence
wpfaMumif;wGif vowel rnfrQyg0ifonfudk &SmazGa&wGufaom Program wpfyk'f
jzpfygonf/
/*Vowel count*/
#include<stdio.h>
#include<ctype.h>
void main()
{
char st[81];
int i,count;
puts(“Enter an Sentence”);
gets(st);
for (i=count=0;st[i];i++)
switch (toupper(st[i]))
{
case ‘A’:
case ‘E’:
case ‘I’:
case ‘O’:

Contents

TurboC

50

uuuGef

case ‘U’:
count++;
}
printf(“\nYour Sentence is %d vowel.”,count);
}

avhusifhcef;(11)
70/ atmufyg Program onf Function rsm;udk ac:,ltoHk;jyKí Manu rS A udk
½dkufxnfhygu *Pef;ESpfvHk;\ aygif;jcif;? S udk ½dkufxnfhygu *Pef;ESpfvHk;\ EIwfjcif;?
M udk ½dkufxnfhygu *Pef;ESpfajrmufjcif;? D udk ½dkufxnfhygu yxr*Pef;udk
pkwd,*Pef;jzifh pm;í &aom&v'fudkjyoay;jcif;? Q udk ½dkufxnfhygu Menu rS
xGufapaom Program wpfyk'f jzpfygonf/
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
void main(void);
char selection(void);
float add(float,float);
float sub(float,float);
float mul(float,float);
float div(float,float);
void menu(void)
{ clrscr();
printf(“\nAddition”);
printf(“\nSubstraction”);
printf(“\nMultiplication”);

Contents

TurboC

51

printf(“\nDivision”);
printf(“\nQuit”);
printf(“\n\nEnter Your Option(A or S or M or D or Q) = “);
}
char selection(void)
{
return(toupper(getch()));
}
float add(float a, float b)
{
return(a+b);
}
float sub(float a, float b)
{
return(a-b);
}
float mul(float a, float b)
{
return(a*b);
}
float div(float a, float b)
{

uuuGef

Contents

52

TurboC

uuuGef

return(a/b);
}
void main(void)
{ clrscr();
float x,y;
char c;
printf(“\nEnter two value > “);
scanf(“%f%f”,&x,&y);
menu();
c=selection();
while (c !=’Q’)
{switch(c)
{ case ‘A’: printf(“\nAddition of two number %0.2f + %0.2f
=%10.2f”,x,y,add(x,y));break;
case ‘S’: printf(“\nSubstraction of two number %0.2f %0.2f=%10.2f”,x,y,sub(x,y));break;
case ‘M’: printf(“\nMultiplication of two number %0.2f *
%0.2f=%10.2f”,x,y,mul(x,y));break;
case ‘D’: if (y) printf(“\nDivision of two number %0.2f /
%0.2f=%10.2f”,x,y,div(x,y));
else printf(“Division by zeros”);break;
default:printf(“Wrong Entery”);
}
printf(“\nStrike anykey to contiune”);
getch();
menu();

Contents

53

TurboC

uuuGef

c=selection();
}
}

avhusifhcef;(12)
71/ atmufyg Program onf character ae&majymif;a&GUaom Program wpfyk'f
jzpfygonf/
/*Character change to next character*/
#include<stdio.h>
void main()
{
char st1[81],st2[81];
int i;
puts(“\nEnter String”);
gets(st1);
for (i=0;st1[i];i++)
st2[i]=st1[i]+1;
st2[i]=’\o’;
puts(st2);
}

avhusifhcef;(13)
72/ atmufyg Program onf Fibonaci number ae&majymif;a&GUaom Program
wpfyk'f jzpfygonf/
#include<stdio.h>
#include<conio.h>

Contents

54

TurboC

uuuGef

main()
{
int i,n,f1,f2,f;
clrscr();
i=f1=f2=1;
printf(“How many Fibonaci numbers ? “);
scanf(“%d”,&n);
do {
if ( i<3)
f=1;
else f=f1+f2;
f2=f1;
f1=f;
printf(“i=%3d

Fibo = %5d\n”,i++,f);

}
while (i<=n);
}

avhusifhcef;(14)
73/ atmufyg Program onf Data File wpfck zefwD;aom Program wpfyk'f
jzpfygonf/
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
main()
{
char ch;

Contents

55

TurboC

uuuGef

FILE *fp = fopen(“myfile.dat”,”w”);
clrscr();
printf(“Enter a line of text : \n”);
do
{
fputc(toupper(ch = getchar()),fp);
}
while (ch != ‘\n’);
fclose(fp);
}

avhusifhcef;(15)
74/ atmufyg Program onf Data File wpfck &SmazGzwf,al om Program wpfy'k f
jzpfygonf/ tu,fí zdik u
f rkd awGUygu Error Cannot open the file. [kjyay;apygonf/
#include<stdio.h>
#include<conio.h>
#define NULL 0
main()
{
FILE *fp;
clrscr();
fp = fopen(“myfile”,”r”);
if (fp == NULL)
printf(“Error Cannot open the file.\n”);
printf(“STOP”);
fclose(fp);
}

Contents

56

TurboC

uuuGef

avhusifhcef;(16)
75/ atmuf y g

Program onf DEFENCE SERVICE COMPUTER
DEPARTMENT qdkonfhpmwef;udk ywfywfvnf; * abmifcwfay;aom Program

wpfyk'f jzpfygonf/
#include<stdio.h>
#include<conio.h>
#define WIDTH

58

#define ROWS

4

line();
sides();
main()
{ clrscr();
line();
sides();
printf(“\t*\t DEFENCE SERVICE COMPUTER DEPARTMENT \t\t
* \n”);
sides();
line();
return 0;
}
line()
{
int i;
for (i=1; i<=WIDTH;i++)
{

Contents

57

TurboC

uuuGef

if ( i==1)
putchar (‘\t*’);
putchar( ‘*’);
}
putchar(‘\n’);
return 0;
}
sides()
{
int i;
for ( i=0; i <= ROWS; ++i)
printf(“\t* \t\t\t\t\t\t\t * \n”);
}

avhusifhcef;(17)
76/ atmufyg Program onf Data File wpfckudk zefwD;NyD; 4if; zdkifudk rqHk;rjcif;
zwfí Output jyKvkyfaom Program wpfyk'f jzpfygonf/
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
main()
{
char ch,*p;
char str[]=”This is File Input/Output Test”;
FILE *fp =fopen (“myfile.dat”,”w”);

Contents

58

TurboC

uuuGef

clrscr();
p = str;
while (*p)
fputc(*p++,fp);
fclose(fp);
fp=fopen(“myfile.dat”,”r”);
while ((ch=fgetc(fp))!=EOF)
putchar(toupper(ch));
fclose(fp);
}

avhusifhcef;(18)
77/ atmufyg Program onf Data File wpfckudk zwfapNyD;zefwD;NyD; 4if; zdkifudk
rqHk;rjcif; zwfí Output jyKvkyfaom Program wpfyk'f jzpfygonf/
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
main()
{
char ch;
int i,count[26];
FILE *fp= fopen(“myfile.dat”,”r”);
clrscr();
for (i=0;i<26;i++)
count[i]=0;
while (ch = fgetc(fp)!=EOF)
{

Contents

TurboC

59

uuuGef

ch = toupper(ch);
putchar(ch);
count[ch-’A’]++;
}
printf(“\n\nCounts of each letter :\n\n”);
for (i=0; i<26;i++)
printf(“%c “,i + ‘A’);
printf(“\n”);
for (i=0; i<26; i++)
printf(“%d “,count[i]);
fclose(fp);
}

avhusifhcef;(19)
78/ atmufyg Program onf Data File wpfckudk zefwD;NyD; 4if; zdkifudk zwfí
zwfí Output jyKvkyfaom Program wpfyk'f jzpfygonf/
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
clrscr();
int i,j,n;
float sum,mean,temp,range,median,stdev,y[50];
FILE *fp1,*fp2;
fp1=fopen(“test.dat”,”r”);
fp2=fopen(“test.out”,”w”);

Contents

60

TurboC
fscanf(fp1,”%d”,&n);
for (i=1; i<=n;++i)
fscanf(fp1,”%f”,&y[i]);
sum=0;
for (i=1;i<=n;++i)
sum += y[i];
mean = sum/n;
for (i=1; i<=(n-1);++i)
for (j=1;j<=n;++j)
if (y[i] > y[j])
{
temp=y[i];
y[i]=y[j];
y[j]=temp;
}
range= y[n] - y[1];
if ((n%2)!=0)
median = y[n/2+1];

else median=(y[n/2] + y[n/2+1])/2;
sum = 0;
for (i=1; i<=n;++i)
sum +=pow((y[i] - mean),2);
stdev = sqrt(sum/(n-1));
printf(“Mean

= %0.2f\n”,mean);

printf(“Median

= %0.2f\n”,median);

printf(“Range

= %0.2f\n”,range);

printf(“Std deviation = %0.2f\n”,stdev);

uuuGef

Contents

61

TurboC

uuuGef

fprintf(fp2, “DATA :\n”);
fprintf(fp2,” n =%d\n”,n);
for (i=1; i<=n;++i)
fprintf(fp2, “%7.1f”,y[i]);
fprintf(fp2,”\n\nRESULT :\n”);
fprintf(fp2,”Mean = %0.2f\n”,mean);
fprintf(fp2,”Median = %0.2f\n”,median);
fprintf(fp2,”Range = %0.2f\n”,range);
fprintf(fp2,”Std deviation = %0.2f\n”,stdev);
}

avhusifhcef;(20)
79/ atmufyg Program onf Hello, world qdo
k nfph maMumif;udk uGeyf sLwm Screen
wGif ay:apatmifa&;om;xm;aom Program wpfyk'f jzpfygonf/
#include<stdio.h>
main()
{
printf(“\nHello, world.\n”);
}

avhusifhcef;(21)
80/ atmufyg Program onf Keyboard rS ½dkufxnfhay;aom number wpfckudk
jyefvnfí uGefysLwm Screen wGif ay:apatmifa&;om;xm;aom Program wpfyk'f
jzpfygonf/
#include<stdio.h>
main()

Contents

TurboC

62

uuuGef

{
float smplNum;
printf(“What sample number do you want to display? “,smplNum);
scanf(“%f”,&smplNum);
printf(“\nThe number you type is %f.\n”,smplNum);
}

avhusifhcef;(22)
81/ atmufyg Program onf bmom&yf ESpcf \
k trSwf 49 rSwx
f ufBu;dD vQif Pass
[k jyay;NyD; 49 rSwfxufi,fygu Fail [k jyay;aom Program wpfyk'f jzpfygonf/
tu,fí Keyboard rS ½dkufxnfhaom trSwfESpfck\trSwfonf 0 xufi,fvQif
(odkYr[kwf) 100 xufBuD;vQif Invali mark entry [k jyoay;apygonf/
#include<stdio.h>
main()
{
int sub1,sub2;
printf(“Enter two subject > “);
scanf(“%d %d”,&sub1,&sub2);
if (sub1<0 || sub1>100 || sub2<0 || sub2>100) printf(“Invali mark
entry”);
else if (sub1>49 && sub2 >49) printf(“Pass”);
else printf(“Fail”);
}

avhusifhcef;(23)
82/ atmufyg Program onf Keyboard rS ½dkufxnfhay;aom Welcome to
Defence Service Computer Department udkuGefysLwm Screen wGif ay:apatmif
a&;om;xm;aom Program wpfyk'f jzpfygonf/

Contents

TurboC

63

uuuGef

/*printf()*/
#include<stdio.h>
main()
{
printf(“\nWelcome to Defence Service Computer Department”);
}

avhusifhcef;(24)
83/ atmufyg Program onf Keyboard rS ½dkufxnfhay;aom Number
udu
k eG yf sLwm Screen wGif ay:apatmif a&;om;xm;aom Program wpfy'k f jzpfygonf/
/*scanf()*/
#include<stdio.h>
main()
{
int num;
printf(“\nEnter Number “);
scanf(“%s”,&num);
printf(“You Type number %d”,num);
}

avhusifhcef;(25)
84/ atmufyg Program onf Keyboard rS ½dkufxnfhay;aom Character udk
getchar function udk toH;k jyKí uGey
f sLwm Screen wGif ay:apatmif a&;om;xm;aom
Program wpfyk'f jzpfygonf/
/*getchar()*/
#include<stdio.h>
main()

Contents

TurboC

64

uuuGef

{
char ch;
printf(“\nEnter Character “);
ch=getchar();
printf(“\nYou Type %c “,ch);
}

avhusifhcef;(26)
85/ atmufyg Program onf Keyboard rS ½dkufxnfhay;aom Character udk
getche function udk toH;k jyKí uGey
f sLwm Screen wGif ay:apatmif a&;om;xm;aom
Program wpfyk'f jzpfygonf/
/*getche()*/
#include<stdio.h>
#include<conio.h>
main()
{
char ch;
printf(“\nEnter Character “);
ch=getche();
printf(“\nYou Type %c “,ch);
}

avhusifhcef;(27)
86/ atmufyg Program onf Keyboard rS ½dkufxnfhay;aom Character udk
getch function udk toH;k jyKí uGey
f sLwm Screen wGif ay:apatmif a&;om;xm;aom
Program wpfyk'f jzpfygonf/

Contents

TurboC

65

uuuGef

/*getch()*/
#include<stdio.h>
#include<conio.h>
main()
{
char ch;
printf(“\nEnter Character “);
ch=getch();
printf(“\nYou Type %c “,ch);
}

avhusifhcef;(28)
87/ atmufyg Program onf Keyboard rS ½dkufxnfhay;aom Character udk
getc function udk toHk;jyKí uGefysLwm Screen wGif ay:apatmif a&;om;xm;aom
Program wpfyk'f jzpfygonf/
/*getc()*/
#include<stdio.h>
main()
{
char ch;
printf(“\nEnter Character “);
ch=getc(stdin);
printf(“\nYou Type %c “,ch);
}

avhusifhcef;(29)
88/ atmufyg Program onf Keyboard rS ½dkufxnfhay;aom Character udk
putchar function udk toH;k jyKí uGey
f sLwm Screen wGif ay:apatmif a&;om;xm;aom

Contents

TurboC

66

uuuGef

Program wpfyk'f jzpfygonf/
/*putchar()*/
#include<stdio.h>
main()
{
char ch;
printf(“\nEnter Character “);
scanf(“%c”,&ch);
putchar(ch);
}

avhusifhcef;(30)
89/ atmufyg Program onf Keyboard rS ½dkufxnfhay;aom Character udk
gets function udk toHk;jyKí uGefysLwm Screen wGif ay:apatmif a&;om;xm;aom
Program wpfyk'f jzpfygonf/
/*gets()*/
#include<stdio.h>
main()
{
char str[80];
printf(“\nEnter a String “);
gets(str);
printf(“%s”,str);
}

avhusifhcef;(31)
90/ atmufyg Program onf Keyboard rS ½dkufxnfhay;aom Character udk

Contents

TurboC

67

uuuGef

puts function udk toHk;jyKí uGefysLwm Screen wGif ay:apatmif a&;om;xm;aom
Program wpfyk'f jzpfygonf/
/*puts()*/
#include<stdio.h>
main()
{
char str[80];
printf(“\nEnter a String “);
gets(str);
puts(str);
}

avhusifhcef;(32)
91/ atmufyg Program onf color jzifh Main Menu program wpfckudk
uGefysLwm Screen wGif ay:apatmif a&;om;xm;aom Program wpfyk'f jzpfygonf/
#include<conio.h>
main()
{
textbackground(7);clreol();textcolor(6);
gotoxy(20,1);cprintf(“Defence Service Computer Department”);
gotoxy(1,25);clreol();textattr(4+(7<<4)+128);
gotoxy(28,25);cprintf(“Press any key to continue”);clreol();
textbackground(7);window(25,4,55,20);clrscr();
textattr(4+(6)<<4);textcolor(11);gotoxy(12,3);cprintf(“Main
Menu”);
gotoxy(12,4);cprintf(“=========”);

Contents

TurboC

68

uuuGef

gotoxy(10,6);cprintf(“A”);
gotoxy(10,8);cprintf(“S”);
gotoxy(10,10);cprintf(“M”);
gotoxy(10,12);cprintf(“D”);
gotoxy(10,14);cprintf(“Q”);
textattr(0+(7<<4));
textcolor(10);gotoxy(11,6);cprintf(“ddition”);
textcolor(10); gotoxy(11,8);cprintf(“ubstraction”);
textcolor(10); gotoxy(11,10);cprintf(“ultiplication”);
textcolor(10); gotoxy(11,12);cprintf(“ivision”);
textcolor(10); gotoxy(11,14);cprintf(“uit to Dos”);
window(30,22,50,23);textbackground(14);clrscr();
window(1,1,60,25);gotoxy(10,22);
textcolor(10); highvideo();cprintf(“WELCOME “);
textcolor(10); lowvideo();cprintf(“TO DEFENCE SERVICE COMPUTER DEPARTMENT”);
normvideo();
getch();clreol();
}

avhusifhcef;(33)
92/ atmufyg Program onf &SdNyD;om; data file udk Main Menu program rS
wpfqifh insert, display, edit, delete, search, sort wdkYrS wpfckudka&G;cs,fí
vkyfaqmifapaom Program wpfyk'f jzpfygonf/
#include<string.h>
#include<stdlib.h>
#include<ctype.h>

Contents

TurboC

69

uuuGef

#include<stdio.h>
#include<conio.h>
struct student
{ char name[15];int mark;};
void insert();
void display();
void edit();
void delet();
void search();
main()
{ int answer;
window(30,2,60,2);textbackground(1);clrscr();
window(30,2,60,2);textbackground(1);clrscr();window(1,1,80,25);
gotoxy(31 ,2);textcolor(15);cprintf(“STUDENT RECORD MAIN
MENU\n”);
window(25,4,60,10);textbackground(1);clrscr();window(1,1,80,25);
gotoxy(26,5);textcolor(15);cprintf(“1. DISPLAY STUDENT
RECORD\n”);
gotoxy(26,6);textcolor(15);cprintf(“2. INSERT STUDENT
RECORD\n”);
gotoxy(26,7);textcolor(15);cprintf(“3. EDITITING STUDENT
RECORD\n”);
gotoxy(26,8);textcolor(15);cprintf(“4. DELETE STUDENT
RECORD\n”);
gotoxy(26,9);textcolor(15);cprintf(“5. SEARCHING STUDENT
RECORD\n”);

Contents

70

TurboC

uuuGef

gotoxy(26,10);textcolor(15);cprintf(“6. QUIT\n”);
gotoxy(20,12);printf(“Choose any one 1,2,3,4,5 and 6 :
“);answer=getche();
switch(answer)
{ case ‘1’: display();break;
case ‘2’: insert();break;
case ‘3’: edit();break;
case ‘4’: delet();break;
case ‘5’: search();break;
case ‘6’: exit(0);
}
getch();
}

void insert()
{
FILE *fp;struct student temp; char ans;
fp=fopen(“file.dat”,”a+b”);
do
{ printf(“\nName : “);gets(temp.name);fflush(stdin);
printf(“Mark : “);scanf(“%d”,&temp.mark);fflush(stdin);
printf(“\nSave [Y/N]”); ans=getch();
if (toupper(ans)==’Y’) fwrite(&temp,sizeof(temp),1,fp);
printf(“\n\nAny more [Y/N]: “);ans=getch();
}while (toupper(ans)!=’N’);
fclose(fp);

Contents

71

TurboC

uuuGef

display();
}
void display()
{ window(30,2,60,2);textbackground(1);clrscr();
FILE *fp; struct student temp; int n=0;
fp=fopen(“file.dat”,”rb”);
printf(“\nSr.No

Name

Mark\n”);

printf(“~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n”);
while (fread(&temp,sizeof(temp),1,fp))
printf(“%3d.\t%-15s\t%3d\n”,++n,temp.name,temp.mark);
fclose(fp);
}
void edit()
{
int s,n,m; FILE *fp; struct student temp;
s=sizeof(temp);
fp=fopen(“file.dat”,”r+b”);
printf(“\nWhich record you want to edit ? “);scanf(“%d”,&n);
fseek(fp,(n-1)*s,SEEK_SET);
fread(&temp,s,1,fp);
printf(“Name =%s Mark=%d\n”,temp.name,temp.mark);
printf(“Change mark to ? “);scanf(“%d”,&m);
temp.mark=m;
fseek(fp,-s,SEEK_CUR);
fwrite(&temp,s,1,fp);

Contents

72

TurboC

uuuGef

fclose(fp);
display();
}
void delet()
{
FILE *fp, *fout; char dname[15]; struct student temp;
fflush(stdin);
printf(“\nEnter name you want delete “);gets(dname);
fp=fopen(“file.dat”,”rb”);
fout=fopen(“temp.dat”,”wb”);
while(fread(&temp,sizeof(temp),1,fp))
{

if(strcmp(temp.name,dname))
fwrite(&temp,sizeof(temp),1,fout);

}
fclose(fp);fclose(fout);
remove(“file.dat”);rename(“temp.dat”,”file.dat”);
display();
}
void search()
{
FILE *fp; char sname[15];int flag=0; struct student temp;
fp=fopen(“file.dat”,”rb”);
printf(“\nEnter name to be search “);gets(sname);
printf(“Name

Mark\n”);

printf(“~~~~~~~~~~~~~~~~~~~~~\n”);

Contents

73

TurboC

uuuGef

while(fread(&temp,sizeof(temp),1,fp))
if(strcmp(temp.name,sname)==0)
{ printf(“%-15s\t%3d\n”,temp.name,temp.mark);
flag=1;
}
if(flag==0)printf(“Not found”);
}

avhusifhcef;(34)
93/ atmufyg Program onf Password program udk a&;om;xm;aom Program
wpfyk'f jzpfygonf/
#include<conio.h>
#include<string.h>
#include<dos.h>
void invalid_message(void);
void pass_background(void);
main()
{
char buffer[4090];
char *OriginalPassword=”DSCD”;
char *EntryPassword;
int RepeatCount;
struct date d; struct time t;
window(10,5,70,20);
textbackground(7);clrscr();window(1,1,80,25);
textattr(2+(7<<44)); gotoxy(12,6);cprintf(“Press any key.. “);
textattr(0+(7<<44)); gotoxy(16,10);

Contents

74

TurboC

uuuGef

cprintf(“This is Original window!”);getch();
gettext(1,1,80,25,buffer); pass_background();
RepeatCount=0;
do
{
RepeatCount++; gotoxy(39,12);
EntryPassword=getpass(“”);
if (RepeatCount>=3)
{
invalid_message();return 0;
}
}while(strcmp(OriginalPassword,EntryPassword)!=0);
window(10,10,70,20);textbackground(7);clrscr();window(1,1,80,25);
window(10,11,69,19);textbackground(3);clrscr();window(1,1,80,25);
textattr(15+(3<<4));
gotoxy(12,12);cprintf(“Today Date : “);
gotoxy(12,14);cprintf(“Time: “);
gotoxy(20,16);cprintf(“Press any key to quit”);
getdate(&d);textattr(14+(3<<4));
gotoxy(24,12);cprintf(“%d/%d/%d”,d.da_mon,d.da_day,d.da_year);
do
{
gotoxy(24,14);gettime(&t);
cprintf(“%2d:%02d:%02d\n”,t.ti_hour,t.ti_min,t.ti_sec,t.ti_hund);
}while(!kbhit());
puttext(1,1,80,25,buffer); getch(); return 0;
}

Contents

TurboC

75

uuuGef

void pass_background()
{
window(20,10,60,14);textbackground(3);clrscr();window(1,1,80,25);
window(20,10,60,10);textbackground(1);clrscr();window(1,1,80,25);
gotoxy(22,10);textattr(7+(1<<4));cprintf(“Password entry”);
gotoxy(22,12);textattr(0+(3<<4));cprintf(“Entry password”);
textbackground(7);cprintf(“%20s”,” “);
}
void invalid_message()
{
window(20,10,60,14);textbackground(3);clrscr();window(1,1,80,25);
window(20,10,60,10);textbackground(1);clrscr();window(1,1,80,25);
gotoxy(22,10);textattr(7+(1<<4));cprintf(“Invalid password”);
gotoxy(22,12);textattr(0+(3<<4));cprintf(“Unauthorized user!
System Quit.”);
getch();
}

avhusifhcef;(35)
94/ atmufyg Program onf Password program udk aemufwpfenf;jzifh a&;om;
xm;aom Program wpfyk'f jzpfygonf/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
void invalid_message(void);

Contents

76

TurboC

uuuGef

void pass_background(void);
main()
{
char buffer[4090];
char *OriginalPassword=”DSCD”;
char *EntryPassword;
int RepeatCount;
struct date d; struct time t;
gotoxy(12,6);printf(“Press any key.. “);
gotoxy(16,10);
/*printf(“This is Original window!”);*/getch();
gettext(1,1,80,25,buffer); pass_background();
RepeatCount=0;
do
{
RepeatCount++; gotoxy(39,12);
EntryPassword=getpass(“”);
if (RepeatCount>=3)
{
invalid_message();return 0;
}
}while(strcmp(OriginalPassword,EntryPassword)!=0);
gotoxy(12,15);printf(“Today Date : “); gotoxy(12,16);printf(“Time:
“);
gotoxy(20,20);cprintf(“Press any key to quit”);
getdate(&d);
gotoxy(24,15);printf(“%d/%d/%d”,d.da_mon,d.da_day,d.da_year);

Contents

77

TurboC

uuuGef

do
{
gotoxy(24,16);gettime(&t);
printf(“%2d:%02d:%02d\n”,t.ti_hour,t.ti_min,t.ti_sec,t.ti_hund);
}while(!kbhit());
puttext(1,1,80,25,buffer); getch(); return 0;
}
void pass_background()
{ gotoxy(22,10);printf(“Password entry”);
gotoxy(22,12);printf(“Entry password”);
printf(“%20s”,” “);
}
void invalid_message()
{ gotoxy(22,10);printf(“Invalid password”);
gotoxy(22,12);printf(“Unauthorized user! System Quit.”);
getch();
}

avhusifhcef;(36)
95/ atmufyg Program onf ude;f ao number ESpv
f ;kH udk Arithmetic Operators
Increment ESifh Decrement udk toHk;jyKí aygif;jcif;udk&Smaom Program wpfyk'f
jzpfygonf/
#include<stdio.h>
#include <conio.h>
main()
{

Contents

78

TurboC

uuuGef

clrscr();
int a,b,sum;
a=5;b=5;
sum=a+b; printf(“a=%d b=%d sum=%d\n”,a,b,sum);
sum=a++ +b; printf(“a=%d b=%d sum=%d\n”,a,b,sum);
sum=++a +b; printf(“a=%d b=%d sum=%d\n”,a,b,sum);
sum= —a +b; printf(“a=%d b=%d sum=%d\n”,a,b,sum);
sum=a — +b; printf(“a=%d b=%d sum=%d\n”,a,b,sum);
getch();
}

avhusifhcef;(37)
96/ atmufyg Program onf t*Fvyd t
f rSww
f pfcu
k kd ½du
k x
f nfv
h u
kd af omtcg trSwf
40 ESifhtxufjzpfvQif atmif[k jyay;NyD; 40 atmufi,fu ½IH;[kjyay;yg &Smaom
Program wpfyk'fjzpfygonf/
#include<stdio.h>
main()
{
int m;
printf(“Enter English marks for a student “);
scanf(“%d”,&m);
if (m<0 || m>100)
printf(“Invalid marks entry “);
else if (m>=40) printf(“Pass”);
else printf(“Fail”);
}

Contents

79

TurboC

uuuGef

avhusifhcef;(38)
97/ atmuf y g Program onf vpmwpf c k u d k ½d k u f x nf h v d k u f a omtcg
owfrw
S af y;aom vpmuefo
Y wfEiS hf udu
k n
f v
D Qif 4if; vpmESihf contribution udk jyay;Ny;D
uefYowfcsufESifhrudkufnDu yHkao contribution 5 [k jyay;&ef a&;om;xm;aom
Program wpfyk'fjzpfygonf/
#include<stdio.h>
main()
{

int salary, contribution;
printf(“Enter you salary:”); scanf(“%d”, &salary);
switch (salary) {
case 1000: contribution=10;break;
case 1500: contribution=20;break;
case 2000: contribution=30;break;
default: contribution=5;
}

/*Switch end */

printf(“You pay %d kyats for the contribution
%d”,salary, contribution);
}

avhusifhcef;(39)
98/ atmufyg Program onf do while looping udk Main Menu program rS
1(odkYr[kwf) 2(odkYr[kwf) 3 udk ½dkufxnfhygu oufqdkif vkyfaqmifcsufudk vkyfapaom
Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
main()
{

Contents

80

TurboC

uuuGef

char ch;
textbackground(1);clrscr();
do{
printf(“1:Entery\n”);
printf(“2:Display\n”);
printf(“3:Quit\n”);
printf(“Choose anymore: “);
ch=getch();
switch(ch)
{
case ‘1’:printf(“\nEnter Module\n\n”);break;
case ‘2’:printf(“\nDisplay Module\n\n”);break;
}
}while(ch!=’3');
}

avhusifhcef;(40)
99/ atmufyg Program onf Array xJ&dS *Pef;rsm;\ aygif;v'fEiS hf ysr;f rQwefb;kd udk
&Smaom Program wpfyk'fjzpfygonf/
#include<stdio.h>
main()
{
int i,a[10],sum,n;
float avg;
printf(“\nEnter total no of elements in the array “);
scanf(“%d\n”,&n);
for (i=0;i<n;i++)

Contents

81

TurboC

uuuGef

scanf(“%d”,&a[i]);
sum=a[0];
for (i=1;i<n;i++)
sum +=a[i];
printf(“\nSum of the array is %d”,sum);
avg=sum*1.0/n;
printf(“\nAverage of the arry is %6.2f”,avg);
}

avhusifhcef;(41)
100/ atmufyg Program onf Array xJ&Sd *Pef;rsm;rS &Smvdk*Pef;udk awGUvQif
awGUaomaeudjk yay;&efEiS hf rawGUygu NOt Found [k jyay;&efa&;om;aom Program
wpfy'k jf zpfygonf/
#include<stdio.h>
main()
{
int i,a[10],num,n,found=0;
printf(“\nEnter total no of element in the array “);
scanf(“%d”,&n);
for (i=0;i<n;i++)
scanf(“%d”,&a[i]);
printf(“\nEnter a number to be searched “);
scanf(“%d”,&num);
for (i=0;i<n;i++)
if (num ==a[i])
{ printf(“%d is found at position %d”,num,i);
found =1;

Contents

82

TurboC

uuuGef

}
if (found ==0) printf(“Not found\n”);
}

avhusifhcef;(42)
101/ atmufyg Program onf Array \ Range udk 5 ckowfrw
S af y;Ny;D Array xJ&dS
*Pef; 5 vHk;udk tpDtpOftvdkuf ay;aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#define n 5
main()
{
int a[n]={67,45,89,12,6};
int i,j,temp;
for (i=0;i<5;i++)
for (j=0;j<(n-i);j++)
if (a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
printf(“\nSorted order\n”);
for (j=1;j<=n;j++)
printf(“%5d”,a[j]);
}

Contents

83

TurboC

uuuGef

avhusifhcef;(43)
102/ atmufyg Program onf String xJ&Sd Character, vowel, Upperletter,
Lowerletter, numeric wdkYudk a&wGufay;aom Program wpfyk'fjzpfygonf/
#include<ctype.h>
#include<stdio.h>
#include<string.h>
main()
{
int l,i,vcount,ncount, acount, lcount,ucount; char st[81];
vcount=ncount=acount=lcount=ucount=0;
puts(“Eenter the string “);gets(st);
l=strlen(st);
for (i=0;i<l;i++)
{
switch (toupper(st[i]))
{
case ‘A’:
case ‘E’:
case ‘I’:
case ‘O’:
case ‘U’:vcount++;
}
if (isdigit(st[i]))ncount++;
if (isalpha(st[i]))acount++;
if (islower(st[i]))lcount++;
if (isupper(st[i]))ucount++;
}

Contents

TurboC

84

uuuGef

puts(“The given sentence is “);puts(st);
printf(“Your sentence has %d vowels\n”,vcount);
printf(“Your sentence has %d numeric character\n”,ncount);
printf(“Your sentence has %d alphabetic character\n”,acount);
printf(“Your sentence has %d lower case character\n”,lcount);
printf(“Your sentence has %d upper case character\n”,ucount);
}

avhusifhcef;(44)
103/ atmuf y g Program onf String ES p f c k xJ & S d Sentence t&S n f u d k
EIdif;,SOfay;aom Program wpfyk'fjzpfygonf/
#include<string.h>
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int i; char st1[81],st2[81],st3[81];
puts(“Enter first string : “);gets(st1);
puts(“Enter second string : “); gets(st2);
if (strcmp(st1,st2)>0) puts(“First string is Larger than the second
string\n”);
else if (strcmp(st1,st2)<0)puts(“First string is smaller than the
second string\n”);
else puts(“Indentcal string”);
printf(“Equialent Upper case sentence is “);puts(strupr(st1));
strcpy(st3,strcat(st1,st2));

Contents

85

TurboC

uuuGef

printf(“\nConcateneated striing :”);puts(st3);
}

avhusifhcef;(45)
104/ atmufyg Program onf Character Array String wpfck xJ&dS character udk
&SmazGaom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<string.h>
main()
{
int i,found=0;char st[10];
char *p[3]={“One”,”Two”,”Three”};
for (i=0;i<3;i++)
printf(“%s\n”,p[i]);
printf(“Enter a search string : “);gets(st);
for (i=0;i<3;i++)
if (strcmp(st,p[i])==0)
{
printf(“Found at position %d\n”,i);
found=1;
}
if (found ==0) printf(“Not found\n”);
}

avhusifhcef;(46)
105/ atmufyg Program onf rdrx
d nfah y;xm;aom trnfrsm;udk Spacebar ESyd yf gu
wpfvSnfhpD ay:apaom Program wpfyk'fjzpfygonf/

Contents

86

TurboC

uuuGef

#include<conio.h>
#define _enter 13
#define _spacebar 32
main()
{
char *UserNames[]={“Kyaw Kyaw”,
“Tun Tun”,
“Win Lwin”,
“Ko Ko”,
“Myint Thu”,
“Kyaw Min Tun”};
int key, count;
window(20,8,50,10);textbackground(7);clrscr();window(1,1,50,25);
gotoxy(22,9);textcolor(0);cprintf(“User Name : “);
textbackground(1); cprintf(“%14s”,” “);
count = key = 0; textcolor(15);
do
{
gotoxy(34,9);cprintf(“%-14s”,UserNames[count]);
gotoxy(34,9);key=getch();
if (key==_spacebar)
{ if (count==5) count=0;
else count++;
}
}while(key!=_enter);
window(20,8,60,10);textbackground(7);clrscr();window(1,1,80,25);
gotoxy(28,9);textcolor(14);

Contents

TurboC

87

uuuGef

cprintf(“You choose %s”,UserNames[count]);
getch();
}

avhusifhcef;(47)
106/ atmufyg Program onf Pointter udk toHk;jyKí rdrdxnfhay;vdkaom
aumsi;f om;ta&twGuEf iS hf bmom&yfEpS cf \
k trSwrf sm;udk ½du
k x
f nfah y;í 4if;trSwrf sm;
xJrS trsm;qHk;bmom&yf trSwfudk jyay;aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<string.h>
#include<conio.h>
typedef struct
{ char name[15];
int bcp,cp;
float avg;
} student;
void entry();
void display();
void max_bcp();
student ncc,max,a[100];
int i,j,n;
main()
{
clrscr();
entry();display();max_bcp();

Contents

88

TurboC

uuuGef

}
void entry()
{
printf(“Enter total no of students “);scanf(“%d”,&n);fflush(stdin);
for (i=0;i<n;i++)
{
printf(“Enter name : “);scanf(“%[A-Zaz]”,&ncc.name);fflush(stdin);
printf(“Enter BCP Marks : “);scanf(“%d”,&ncc.bcp);fflush(stdin);
printf(“Enter CP Marks : “);scanf(“%d”,&ncc.cp);fflush(stdin);
ncc.avg=(ncc.bcp+ncc.cp)*1.0/2;
a[i]=ncc;
}
}
void display()
{
clrscr();
gotoxy(25,1); printf(“NCC STUDENT LIST\n”);
gotoxy(25,2); printf(“————————\n”);
printf(“Name

BCP CP

AVERAGE\n”);

printf(“——————————————————————\n”);
for (i=0;i<n;i++)
printf(“%-15s%5d%5d%7.2f\n”,a[i].name,a[i].bcp,a[i].cp,a[i].avg);
printf(“——————————————————————\n”);
printf(“Press any key to continue\n”);getch();

Contents

TurboC

89

uuuGef

}
void max_bcp()
{
clrscr();
printf(“Maximum BCP marks for the given student \n”);
max=a[0];
for (i=1;i<n;i++)
if (a[i].bcp>max.bcp) max=a[i];
printf(“Name = %s \n”,max.name);
printf(“BCP = %d \n”,max.bcp);
printf(“CP = %d \n”,max.cp);
printf(“Average = %7.2f \n”,max.avg);
getch();
}

avhusifhcef;(48)
107/ atmufyg Program onf Function udk toH;k jyKNy;D Array string xJ&dS Character
rsm;udk a&wGufay;aom Program wpfyk'fjzpfygonf/
#include<string.h>
#include<stdio.h>
#include<conio.h>
void strdisplay(char*);
main()
{
char UserStr[80]; UserStr[0]=’\0';
clrscr(); printf(“Enter string : “);gets(UserStr);
strdisplay(UserStr); getch();

Contents

TurboC

90

uuuGef

}
void strdisplay(char* UserStr)
{
int count, lenght;
lenght=strlen(UserStr);
printf(“Total no of character = %d\n”,lenght);
for (count=0;count<+lenght;count++)
printf(“UserStr[%d]=[%c]\n”,count,UserStr[count]);
}

avhusifhcef;(49)
108/ atmufyg Program onf Pointer udk toHk;jyKNyD; ausmif;om;rsm; ½lyaAESifh
"gwkaA' trSwfrsm;? ysrf;rQtrSwfrsm;udk &Smaom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
struct student
{ char name[15]; char sex;
int phys,chem; float avg;
};
struct student entry();
void display(struct student s);
main()
{
clrscr();
struct student temp=entry();
display(temp);

Contents

91

TurboC

uuuGef

}
struct student entry()
{
struct student s;
clrscr();
printf(“Enter Name = “); gets(s.name);fflush(stdin);
printf(“Enter Sex = “);scanf(“%c”,&s.sex);fflush(stdin);
printf(“Enter Physics = “);scanf(“%d”,&s.phys);fflush(stdin);
printf(“Enter Chemisty = “);scanf(“%d”,&s.chem);fflush(stdin);
s.avg=(s.phys+s.chem)/2.0;
return s;
}
void display(struct student s)
{
clrscr();
printf(“Name = %s\n”,s.name); printf(“Sex = %c\n”,s.sex);
printf(“Physics = %d\n”,s.phys);printf(“Chemisty = %d\n”,s.chem);
printf(“Average = %6.2f\n\n”,s.avg);
}

avhusifhcef;(50)
109/ atmufyg Program onf *Pef;ESpfvHk; ½dkufxnfhNyD; taygif;? tEIwf? tjrmuf?
tpm;wdkYudk wGufcsufay;aom Program wpfyk'fjzpfygonf/
#include<conio.h>

Contents

92

TurboC

uuuGef

#include<stdio.h>
main()
{
int a,b; char ans;
textbackground(1);clrscr(); gotoxy(10,5);
printf(“Enter two integer number to
calculate:”);scanf(“%d%d”, &a,&b);
gotoxy(10,7); printf(“1:Addition”);
gotoxy(10,9); printf(“2:Substraaction”);
gotoxy(10,11); printf(“3:Multiplication”);
gotoxy(10,13); printf(“4:Division”);
gotoxy(10,15); printf(“Choose any one:”);
ans=getche();
switch(ans)
{
case’1': printf(“\n\n%d+%d=%d”,a,b,a+b);break;
case’2': printf(“\n\n%d-%d=%d”,a,b,a-b);break;
case’3': printf(“\n\n%d*%d=%d”,a,b,a*b);break;
case’4': printf(“\n\n%d/%d=%d remainder %d”,a,b,a/b,a%b);
}
getch();
}

avhusifhcef;(51)
110/ atmufyg Program onf Array \ Size udk 100 owfrSwfay;xm;NyD; 4if;
Array xJodkY rdrdxnfhvdkaom *Pef; ta&twGufudk xnfhay;EdkifNyD;? 4if; Array xJrS
rdrd&Smvdkaom *Pef;udk &Smaom Program wpfyk'fjzpfygonf/

Contents

93

TurboC

uuuGef

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int A[100],i,n,num,temp,found=0;
cout<<“Hown many number ? > “;
cin>>n;
for(i=0;i<n;i++)
cin>>A[i];
cout<<“Enter search number? “;
cin>>num;
i=0;
while (i<n && !found)
{
if (num==A[i])
found=1;
else i++;
}
if (found) cout<<“Found!”;
else cout<<“Not Found”;
}

avhusifhcef;(52)
111/ atmufyg Program onf if function udt
k oH;k jyKí *Pef;wpfv;kH udk ½du
k x
f nfNh y;D
4if;*Pef;onf Positive (odrYk [kw)f Negative (odrYk [kw)f Zero wdrYk S cGjJ cm;aom Program
wpfy'k jf zpfygonf/

Contents

TurboC

94

uuuGef

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int num;
printf(“\nEnter number “);
scanf(“%d”,&num);
if (num > 0)
printf(“\nPositive number”);
else if(num < 0)
printf(“\nNegative number”);
else if (num==0)
printf(“\nZero number”);
}

avhusifhcef;(53)
112/ atmufyg Program onf ude;f ao 0123456789 *Pef;udk data file wpfcu
k kd
zefwD;wnfaqmufí a&;om;xm;aom Program wpfyk'fjzpfygonf/
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <dos.h>
#include <io.h>
int main(void)
{

Contents

95

TurboC

uuuGef

int handle;
char buf[11] = “0123456789”;
/* attempt to create a file that doesn’t already exist */
handle = creatnew(“DUMMY1.FIL”, 0);
if (handle == -1)
printf(“DUMMY1.FIL already exists.\n”);
else
{
printf(“DUMMY1.FIL successfully created.\n”);
write(handle, buf, strlen(buf));
close(handle);
}
return 0;
}

avhusifhcef;(54)
113/ atmufyg Program onf 'óudef;*Pef;wpfckudk ½dkufxnfhNyD; uGefysLwm
screen wGif jyoay;aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
main()
{ float smplNum;
printf(“What sample number do you want to display? “,smplNum);
scanf(“%f”,&smplNum);
printf(“\nThe number you type is %f.\n”,smplNum);
}

Contents

TurboC

96

uuuGef

avhusifhcef;(55)
114/ atmufyg Program onf rdrd½dkufxnfhay;aom*Pef;oHk;vHk;udk EIdif;,SOfNyD;
tpDtpOfwus pDay;aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
int a,b,c;
void accept();
void swap(int *x, int *y);
main()
{
accept();
if(a>b) swap(&a,&b);
if(b>a) swap(&b,&c);
if(c>a) swap(&a,&b);
printf(“The sorted numbers are: %4d%4d%4d”,a,b,c);
getch();
}
void accept()
{
printf(“\nEnter three integers “);
scanf(“%d%d%d”,&a,&b,&c);
}
void swap(int *x, int *y)
{

Contents

TurboC

97

uuuGef

int temp;
temp=*x;
*x=*y;
*y=temp;
}

avhusifhcef;(56)
115/ atmufyg Program onf rdrd½dkufxnfhay;aom*Pef;wpfvHk;udk Positive,
Negative, Zero cGJjcm;aay;aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int num;
printf(“Enter number “);
scanf(“%d”,&num);
if(num>0)printf(“\nPositive”);
if(num<0)printf(“\nNegative”);
if(num==0)printf(“\nZero”);
}

avhusifhcef;(57)
116/ atmufyg Program onf rdr½d u
kd x
f nfah y;aom*Pef;wpfv;kH udk Prime number
[kwf^ r[kwf cGJjcm;aay;aom Program wpfyk'fjzpfygonf/

Contents

TurboC

98

uuuGef

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int r,num,d=1;
printf(“\nEnter number>”);
scanf(“%d”,&num);
do
{ ++d; r=num%d;}
while (r !=0);
if (num==d)
printf(“\nPrime”);
else printf(“\nNot prime”);
}

avhusifhcef;(58)
117/ atmufyg Program onf Data &SNd y;D om; data file wpfcrk mS data rsm;zwf,Nl y;D
4if; data tBuD;qHk;*Pef;ESifh ti,fqHk;*Pef;rsm;udk Output data file wpfcktjzpf
odrf;xm;aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
void main()
{
int i,n; float number, max,min;
FILE *inf, *outf;
inf=fopen(“pro2.dat”,”r”);

Contents

99

TurboC

uuuGef

outf=fopen(“pro2.out”,”w”);
fscanf(inf,”%d”, &n);
fscanf(inf,”%f”,&number);
max=min = number;
for (i=1;i<n;i++)
{ fscanf(inf,”%f”,&number);
if (number > max) max=number;
else if (number < min) min=number;}
fprintf(outf,”\nMaximun is %10.2f”,max);
fprintf(outf,”\nMinimun is %10.2f”,min);
}

avhusifhcef;(59)
118/ atmufyg Program onf tHpmwHk;upm;aomaom Game Program
wpfy'k jf zpfygonf/
#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<dos.h>
void main()
{ int i,money=500, dno,d,bet,count;
char ans=’Y’;
while (ans==’Y’)
{
do

Contents

100

TurboC
{

printf(“\nEnter your bet: “);scanf(“%d”,&bet);
if (bet > money) printf(“\nNot enough money”);
}while (bet>money);
do
{ printf(“\nEnter dice number”);scanf(“%d”,&d);
if (d<1||d>6)printf(“\nWrong entry “);
}while (d<1||d>6);
count=0;
printf(“\nDicce number are “);
for (i=0;i<3;i++)
{
dno=random(6)+1;
delay(500);
printf(“\n%d”,dno);
if (dno==d)count++;
}
if (count)
{

printf(“\nYou win the game”);
money+=bet * count;

}
else
{

printf(“\nYou lost the game”);
if (!money)
{

printf(“\nYou have no money to play game”);
getch();
exit(1);

uuuGef

Contents

101

TurboC

uuuGef

}
}
printf(“\nMoney =%d”,money);
printf(“\nPlay any more (Y/N)? “);
ans=toupper(getch());
}
}

avhusifhcef;(60)
119/ atmufyg Program onf while looping udk toHk;jyKum vpmaiGrsm;udk
f ykd gu -999 ½du
k af y;&aom
½du
k x
f nfNh y;D vpmaiGrsm; aygif;v'fukd &Smí program rS xGuv
Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int salary,sum;
sum=salary=0;
printf(“\nData entry terminated -999\n”);
while (salary !=-999)
{
sum +=salary;
printf(“\nEnter salary > “);
scanf(“%d”,&salary);
}

Contents

102

TurboC

uuuGef

printf(“\nSum =%d”,sum);
}

avhusifhcef;(61)
120/ atmufyg Program onf switch statement udk toHk;jyKum vpmaiGrsm;udk
½du
k x
f nfNh y;D vpmaiGrsm;onf rnfonfh contribution range wGif yg0ifonfukd az:jyay;
aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
main()
{
int salary,contribution;
printf(“\nEnter salary “);
scanf(“%d”,&salary);
switch(salary)
{
case 750: contribution=5;break;
case 1000: contribution=10;break;
case 1250: contribution=15;break;
case 1400: contribution=20;break;
case 1700: contribution=25;break;
case 2000: contribution=30;break;
default: contribution=3;
}
printf(“You pay %d kyat for the contribution”,contribution);
}
/* Program to create backup of the AUTOEXEC.BAT file */

Contents

103

TurboC

uuuGef

avhusifhcef;(62)
121/ atmufyg Program onf name ESifh birthday udk rdrdaz:jyvdkaom yHkpHjzifh
jyoay;aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
main()
{
int i;
struct date
{
char name[80];
int

month;

int

day;

int

year;

}
struct birthday
{
“Mg Mg”,12,30,93,
“Mg Ba”,5,20,90,
“Mg Hla”,7,15,88,
“Su Su”, 11,29,91,
“Yi Yi”,12,3,94,
“Soe Soe”,4,12,92
};
clrscr();

Contents

104

TurboC

uuuGef

printf(“*****************************\n”);
printf(“ Name

Date birth\n”);

printf(“*****************************\n”);
for (i=0; i<6; ++i)
printf(“%10s%d/%d/%d\n”,birthday[i].name,birthday[i].month,
birthday[i].day,birthday[i].year);
}

avhusifhcef;(63)
122/ atmufyg Program onf Array xJ&Sd *Pef;rsm;\ aygif;v'fudk &Smaom
Program wpfyk'fjzpfygonf/
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int a[10],i,sum,n;
randomize();
cout<<“\nHow many number ? “;
cin>>n;
clrscr();
for ( i=0;i<n;i++)
{ a[i]=random(50)+1;
cout<<a[i]<<‘\n’;
sum+=a[i];
}

Contents

TurboC

105

uuuGef

cout<<“This sum of array=”<<sum;
}

avhusifhcef;(64)
123/ atmufyg Program onf data file rS ausmif;om;rSwfwrf;uddk jyoay;jcif;?
xyfxnfjh cif;? jyKjyifjcif;? zsujf cif;? &SmazGjcif;wdYk jyKvyk af om Program wpfy'k jf zpfygonf/
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<stdio.h>
#include<conio.h>
struct student
{ char name[15];int mark;};
void insert();
void display();
void edit();
void delet();
void search();
main()
{ int answer;
window(30,2,60,2);textbackground(1);clrscr();
window(30,2,60,2);textbackground(1);clrscr();window(1,1,80,25);
gotoxy(31 ,2);textcolor(15);cprintf(“STUDENT RECORD MAIN
MENU\n”);
window(25,4,60,10);textbackground(1);clrscr();window(1,1,80,25);

Contents

106

TurboC

uuuGef

gotoxy(26,5);textcolor(15);cprintf(“1. DISPLAY STUDENT
RECORD\n”);
gotoxy(26,6);textcolor(15);cprintf(“2. INSERT STUDENT
RECORD\n”);
gotoxy(26,7);textcolor(15);cprintf(“3. EDITITING STUDENT
RECORD\n”);
gotoxy(26,8);textcolor(15);cprintf(“4. DELETE STUDENT
RECORD\n”);
gotoxy(26,9);textcolor(15);cprintf(“5. SEARCHING STUDENT
RECORD\n”);
gotoxy(26,10);textcolor(15);cprintf(“6. QUIT\n”);
gotoxy(20,12);printf(“Choose any one 1,2,3,4,5 and 6 :
“);answer=getche();
switch(answer)
{ case ‘1’: display();break;
case ‘2’: insert();break;
case ‘3’: edit();break;
case ‘4’: delet();break;
case ‘5’: search();break;
case ‘6’: exit(0);
}
getch();
}
void insert()
{
FILE *fp;struct student temp; char ans;

Contents

107

TurboC

uuuGef

fp=fopen(“file.dat”,”a+b”);
do
{ printf(“\nName : “);gets(temp.name);fflush(stdin);
printf(“Mark : “);scanf(“%d”,&temp.mark);fflush(stdin);
printf(“\nSave [Y/N]”); ans=getch();
if (toupper(ans)==’Y’) fwrite(&temp,sizeof(temp),1,fp);
printf(“\n\nAny more [Y/N]: “);ans=getch();
}while (toupper(ans)!=’N’);
fclose(fp);
display();
}
void display()
{ window(30,2,60,2);textbackground(1);clrscr();
FILE *fp; struct student temp; int n=0;
fp=fopen(“file.dat”,”rb”);
printf(“\nSr.No

Name

Mark\n”);

printf(“~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n”);
while (fread(&temp,sizeof(temp),1,fp))
printf(“%3d.\t%-15s\t%3d\n”,++n,temp.name,temp.mark);
fclose(fp);
}
void edit()
{
int s,n,m; FILE *fp; struct student temp;
s=sizeof(temp);

Contents

108

TurboC

uuuGef

fp=fopen(“file.dat”,”r+b”);
printf(“\nWhich record you want to edit ? “);scanf(“%d”,&n);
fseek(fp,(n-1)*s,SEEK_SET);
fread(&temp,s,1,fp);
printf(“Name =%s Mark=%d\n”,temp.name,temp.mark);
printf(“Change mark to ? “);scanf(“%d”,&m);
temp.mark=m;
fseek(fp,-s,SEEK_CUR);
fwrite(&temp,s,1,fp);
fclose(fp);
display();
}
void delet()
{
FILE *fp, *fout; char dname[15]; struct student temp;
fflush(stdin);
printf(“\nEnter name you want delete “);gets(dname);
fp=fopen(“file.dat”,”rb”);
fout=fopen(“temp.dat”,”wb”);
while(fread(&temp,sizeof(temp),1,fp))
{

if(strcmp(temp.name,dname))
fwrite(&temp,sizeof(temp),1,fout);

}
fclose(fp);fclose(fout);
remove(“file.dat”);rename(“temp.dat”,”file.dat”);
display();

Contents

109

TurboC

uuuGef

}
void search()
{
FILE *fp; char sname[15];int flag=0; struct student temp;
fp=fopen(“file.dat”,”rb”);
printf(“\nEnter name to be search “);gets(sname);
printf(“Name

Mark\n”);

printf(“~~~~~~~~~~~~~~~~~~~~~\n”);
while(fread(&temp,sizeof(temp),1,fp))
if(strcmp(temp.name,sname)==0)
{ printf(“%-15s\t%3d\n”,temp.name,temp.mark);
flag=1;
}
if(flag==0)printf(“Not found”);
}

avhusifhcef;(65)
124/ atmufyg Program onf while looping udk toHk;jyKNyD; ausmif;om;\
bmom&yf oH;k cktrSwu
f kd ½du
k x
f nfNh y;D aemufxyfausmif;om;wpf\ nmom&yftrSwu
f kd
xyfxnfhrnfqdkaom pmwef;udk ay:apNyD; xyfxnfhvdkygu Y udk ESdyfNyD; rxnfhvdkygu
N udk ESdyfyg/ 4if;aemuf atmif^ ½HI; ta&twGufudk ay;yg[k a&;om;xm; Program
wpfy'k jf zpfygonf/
#include<stdio.h>
#include<conio.h>
main()
{

Contents

110

TurboC

uuuGef

clrscr();
int sub1,sub2,sub3,pass=0,fail=0;
char ch=’Y’;
while (ch ==’Y’|| ch ==’y’)
{
printf(“\nEnter three subject marks : “);
scanf(“%d %d %d”,&sub1,&sub2,&sub3);
if (sub1<50 || sub2<50 || sub3<50)
fail=fail+1;
else
pass=pass+1;
ch=’X’;
printf(“Do you want to another record[y/n] : “);
while (ch !=’Y’ && ch !=’y’ && ch !=’N’ && ch !=’n’)
{
scanf(“%c”,&ch);
}
}
printf(“\nPass =%d”,pass);
printf(“\nFail =%d”,fail);
getch();
}

avhusifhcef;(66)
125/ atmuf y g Program onf Array xJ o d k Y 'órud e f ; rsm;ud k data file
tjzpfodrf;xm;apaom Program wpfyk'fjzpfygonf/

Contents

111

TurboC
#include<stdio.h>
#include<conio.h>
main()
{
float a[20][3],num;
int i;
FILE *fopen(), *f;
f=fopen(“test10.dat”,”w”);
for (i=0;i<20;i++)
{

printf(“\nEnter data position %2d = “,i+1);
scanf(“%f”,&num);
a[i][1]=num;
a[19-i][2]=a[i][1];
}
for (i=0;i<20;i++)
a[i][3]=(a[i][1]+a[i][2]) / 2.0;
clrscr();
printf(“Inorder\tReverse order\tAverage\n”);
printf(“~~~~~~~\t~~~~~~~~~~~~~\t~~~~~~~\n”);
fprintf(f,”Inorder\tReverse order\tAverage\n”);
fprintf(f,”~~~~~~~\t~~~~~~~~~~~~~\t~~~~~~~\n”);
for (i=0;i<20;i++)
{
printf(“%0.2f\t\t%0.2f\t%0.2f\n”,a[i][1],a[i][2],a[i][3]);
fprintf(f,”%0.2f\t\t%0.2f\t%0.2f\n”,a[i][1],a[i][2],a[i][3]);
}

uuuGef

Contents

112

TurboC

uuuGef

fclose(f);
}

avhusifhcef;(67)
126/ atmufyg Program onf Array Size 5 ck xJodkY *Pef;rsm;udk ½dkufxnfhNyD;
Sort jyKvkyfcdkif;aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
main()
{ int i, a[5],j,t;
printf(“Enter first number: “);
scanf(“%d”,&a[0]);
for (i=1;i<5;i++)
{ printf(“Enter next: “);
scanf(“%d”,&a[i]);
}
clrscr();
printf(“Input Data\n”);
for (i=0;i<5;i++)
{
printf(“\t%d”,a[i]);
}
printf(“\n”);
for (i=0;i<5;i++)
for (j=0;j<4-i;j++)
{ if (a[j] >a[j+1])

Contents

113

TurboC

uuuGef

{ t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
printf(“\nSorted data\n”);
for (i=0;i<5;i++)
{
printf(“\t%d”,a[i]);
}
printf(“\n”);
}

avhusifhcef;(68)
127/ atmufyg Program onf pmar;yGJwpfckwGif ausmif;om;rsm;\ atmif? ½HI;?
*kPfxl;&? ausmif;om;ta&twGufudk &Smaom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int sub1,sub2,sub3,pass=0,fail=0,c=0,d=0,count=0;
char ch=’Y’;
while (ch ==’Y’|| ch ==’y’)
{
printf(“\nEnter three subject marks : “);

Contents

114

TurboC

uuuGef

scanf(“%d %d %d”,&sub1,&sub2,&sub3);
if (sub1<50 || sub2<50 || sub3<50) fail=fail+1;
if (sub1>49 && sub2>49 && sub3>49) pass=pass+1;
if (sub1>64 && sub2>64 && sub3>64) c=c+1;
if (sub1>84 && sub2>84 && sub3>84) d=d+1;
count=count+1; ch=’X’;
printf(“Do you want to another record[y/n] : “);
while (ch !=’Y’ && ch !=’y’ && ch !=’N’ && ch !=’n’)
{ scanf(“%c”,&ch);}
}
gotoxy(30,10);printf(“Pass =%d”,pass);
gotoxy(30,11);printf(“Fail =%d”,fail);
gotoxy(30,12);printf(“Crideits =%d”,c);
gotoxy(30,13);printf(“Distanction =%d”,d);
gotoxy(30,14);printf(“Number of Student=%d”,count);
getch();
}

avhusifhcef;(69)
128/ atmufyg Program onf em&DwGif puúefY 60 rS wpfrdepf? rdepf 60 rS wpfem&D
tcsdefoGm;EIef;twdkif; a&;om;xm;aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int i,h,m,s;

Contents

115

TurboC

uuuGef

for (h=0;h<=23;h++)
for (m=0;m<=59;m++)
{ for (s=0;s<=59;s++)
printf(“\n%dh :%dm :%ds “);
for (i=1;i<=50;i++);
}
}

avhusifhcef;(70)
129/ atmufyg Program onf *Pef; ig;vH;k udk aygif;jcif;ESihf ysr;f rQ &Sm;aom Program
wpfy'k jf zpfygonf/
#include<stdio.h>
#include<conio.h>
void main()
{ int i=0,sum=0,num,c;
float avg;
clrscr();
c=0;
while (c<5)
{
printf(“Enter the number “);
scanf(“%d”,&num);
sum +=num;
c++;
}
avg=sum/5;

Contents

116

TurboC

uuuGef

printf(“Sum = %d\n”,sum);
printf(“Average = %.2f”,avg);
getch();
}

avhusifhcef;(71)
130/ atmufyg Program onf rdrd ½du
k x
f nfv
h u
kd af om *Pef;onf oknESihf rnDrjcif;
*Pef;rsm;udk aygif;jcif;ESifh ysrf;rQ &Sm;aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
void main()
{ int i=0,sum=0,num;
float avg;
clrscr();
printf(“Enter the number\t”);
scanf(“%d”,&num);
while (num !=0)
i++;
{
sum +=num;
printf(“Enter the number\t “);
scanf(“%d”,&num);
}
avg=sum/i;
printf(“Sum = %d\n”,sum);
printf(“Average = %.2f”,avg);

Contents

117

TurboC

uuuGef

getch();
}

avhusifhcef;(72)
131/ atmuf y g

Program onf DEFENCE SERVICE COMPUTER

DEPARTMENT qdkpmwef;udk aemufcHta&mifaxmifhrSefpwk*HxJ ay:apatmif

a&;xm;aom Program wpfyk'fjzpfygonf/
#include<conio.h>
main()
{
window(20,1,60,3);textbackground(1);clrscr();window(1,1,80,25);
gotoxy(21,2);textcolor(2);cprintf(“DEFENCE SERVICE COMPUTER DEPARTMENT”);
getch();
}

avhusifhcef;(72)
131/ atmuf y g Program onf Arithmetic Operator ud k toH k ; jyKí
ude;f ao*Pef;ESpv
f ;kH \ aygif;jcif;? EIwjf cif;? ajrmufjcif;ESihf pmjcif;wdu
Yk kd &Smaom Program
wpfy'k jf zpfygonf/
/* Using Arithmetic Operator */
#include<stdio.h>
#include<conio.h>
main()
{

Contents

TurboC

118

uuuGef

clrscr();
int x=20, y=4;
printf(“x=20,\ty=4\n”);
printf(“x + y = %5d\n”,x+y);
printf(“x - y = %5d\n”,x-y);
printf(“x * y = %5d\n”,x*y);
printf(“x / y = %5d\n”,x/y);
getch();
}

avhusifhcef;(73)
132/ atmufyg Program onf Conditional Operator udk toH;k jyKí ½du
k v
f u
kd af om
*Pef;ESpfvHk;rS tBuD;qHk*Pef;udk &Smaom Program wpfyk'fjzpfygonf/
/* Using Conditional Operator(?) */
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a,b,larg;
printf(“Enter two numbers : “);
scanf(“%d,%d”,&a,&b);
larg=(a>b) ? a:b;
printf(“The larger number is %d”,larg);
getch();
}

Contents

119

TurboC

uuuGef

avhusifhcef;(74)
133/ atmufyg Program onf ½dkufxnfhvdkufaom Character String wpfckudk
Puts function toHk;jyKí jyay;cdkif;aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
main()
{ char text[80];
printf(“Enter a sentence\n”);
gets(text);
puts(text);
}

avhusifhcef;(75)
134/ atmufyg Program onf ½dkufxnfhvdkufaom *Pef;av;vHk;xJrS tBuD;qHk;
udef;udk &Smaom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
larger(int a, int b);
main()
{
int num1, num2, num3, num4, larg;
clrscr();
puts (“enter four integer numbers”);
scanf (“%d,%d,%d,%d”, &num1, &num2, &num3, &num4);
larg = larger(larger(num1,num2),larger(num3,num4));

Contents

120

TurboC

uuuGef

printf ( “Largest number = %d”, larg);
}
larger (int a, int b)
{
int c;
c = a > b ? a : b;
return (c);
}

avhusifhcef;(76)
135/ atmufyg Program onf arG;aeYouú&mZf ½dkufxnfhvdkufaom 4if; arG;aeY&Sif
rnfhonfhaeYzGm;udk az:jyay;aom Program wpfyk'fjzpfygonf/
#include<stdio.h>
#include<conio.h>
main()
{
int day,month,year,x,y,z,day_of_week;
char ch;
clrscr();
puts(“Enter a date in the form : day/month/year”);
scanf(“%d%c%d%c%d”,&day,&ch,&month,&ch,&year);
x=year % 100;
y=year / 100;
z=month - 2;
if (z <=0)
{ z +=12;-x;}
day_of_week=((13 * z - 1) / 5+day+x+x / 4+y / 4-2 * y) % 7;
printf(“\n%d/%d/%d is a “,day,month,year);

Contents

TurboC

121

switch (day_of_week)
{ case 0:puts (“Sunday”);break;
case 1:puts (“Monday”);break;
case 2:puts (“Tuesday”);break;
case 3:puts (“Wednesday”);break;
case 4:puts (“Thursday”);break;
case 5:puts (“Friday”);break;
case 6:puts (“Saturday”);break;
}
getch();
}

uuuGef