Professional Documents
Culture Documents
Turbo C
Turbo C
Turbo C
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
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/
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
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
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
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
TurboC
uuuGef
TURBO C PROGRAMMING
tcef;(1)
Turboo C tajccH
ed'gef;
1/
Message
F1 Help F10 Menu
yHk(1)
Contents
TurboC
uuuGef
Contents
TurboC
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/
Contents
TurboC
uuuGef
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
Contents
TurboC
uuuGef
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
TurboC
uuuGef
Arithmetic Operators
16/ Turbo C Program wGif toH;k jyKaom Arithmetic Operators rsm;rSm atmufyg
twdkif;jzpfygonf+
Addition ( taygif; )
Subtraction ( tEkwf )
*
Multiplication ( tajrmuf )
/
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;vJtNru
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)
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 oknjzpfr&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
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 [lif;? Integer data type udk toHk;jyKygu %d [lif;? Float
point data type udk toHk;jyKygu %f [lif;? String data type udk toHk;jyKygu %s
[l a&;om;ay;&ygrnf/Oyrm- printf("Character %c ",ch);
Example 2.1
22/
Contents
TurboC
uuuGef
char smplch;
int smplnum;
smplch = 'a'; smplnum = 9;
printf(The samples are %c and %d.\n,smplch,smplnum);
}
Contents
TurboC
10
uuuGef
Contents
11
TurboC
(C)
(i )
(p )
(q)
(Z )
uuuGef
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 rSkdufxnfhrnfh 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);
}
Contents
TurboC
13
uuuGef
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; zwfvdkaomtcgwGifif; Program Run NyD; &&Sdvmaom
tajzwdk uGefysLwm Screen wGif jyoay;&mwGifif; 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( );
}
Contents
15
TurboC
(c )
(* )
(C)
(i )
(p )
(q)
(Z )
(ps)
uuuGef
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 rSkdufxnfhaom 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);
}
Contents
TurboC
17
uuuGef
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);
}
Contents
19
TurboC
(p )
(q)
(Z )
uuuGef
pmaMumif;ay:atmif a&;xm;jcif;jzpfygonf/
gets function udk toH;k jyKNy;D Keyboard rSu
dk x
f nfah om string wpfcu
k kd
str array wGif assing vkyfvufcHjcif;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);
}
Contents
TurboC
(c )
(* )
(C)
(i )
(p )
(q)
(Z )
20
uuuGef
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 rSu
dk x
f nfah om string wpfcu
k kd
str array xJodkY assing vkyfvufcHjcif;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
Contents
TurboC
(*)
(C)
(C)
22
uuuGef
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
Contents
TurboC
24
uuuGef
Contents
TurboC
25
uuuGef
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");
}
Contents
28
TurboC
(C)
uuuGef
txufyg Program udk Ctrl ESifh F9 key udkESdyf Run rnfqdkygu uGefysLwm
Screen wGif Enter subject mark > [k Data udk Keyboard rSdkufxnfhay;&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;wpfckckudkdkufxnfhay;&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;udk 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");
}
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);
}
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);
}
Contents
TurboC
( *)
35
uuuGef
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);
}
Contents
TurboC
37
uuuGef
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);
}
(c)
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);
}
}
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
( 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 tajrmufvuPm
x i wefbdk; 2 nDrQjcif;vuPm = 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 rdu
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 rdkufbJ 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
avhusifhcef;(4)
63/ atmufyg Program onf ypnf;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
Contents
45
TurboC
printf(~~~~
printf(%s
uuuGef
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
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
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
wpfyk'f jzpfygonf/
#include<stdio.h>
#include<conio.h>
#define WIDTH
58
#define ROWS
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];
= %0.2f\n,mean);
printf(Median
= %0.2f\n,median);
printf(Range
= %0.2f\n,range);
uuuGef
Contents
61
TurboC
uuuGef
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
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
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
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()
{
/*Switch end */
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
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
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
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)
{
case1': printf(\n\n%d+%d=%d,a,b,a+b);break;
case2': printf(\n\n%d-%d=%d,a,b,a-b);break;
case3': printf(\n\n%d*%d=%d,a,b,a*b);break;
case4': 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 doesnt 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 rdrddkufxnfhay;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 rdrddkufxnfhay;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 rdrd 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
{
}
else
{
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
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
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++)
{
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 puefY 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
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
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