0% found this document useful (0 votes)
327 views156 pages

Cpds Manualfd

1. The document contains details of 35 programs with their name and page numbers. 2. The programs include evaluating mathematical expressions, finding areas of shapes, swapping numbers, sorting, matrix operations, file handling, structures, arrays and more. 3. Most programs follow the standard steps of taking input, performing calculations, and displaying output. Functions and loops are used to implement logic in many programs.

Uploaded by

Sitaram Sds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
327 views156 pages

Cpds Manualfd

1. The document contains details of 35 programs with their name and page numbers. 2. The programs include evaluating mathematical expressions, finding areas of shapes, swapping numbers, sorting, matrix operations, file handling, structures, arrays and more. 3. Most programs follow the standard steps of taking input, performing calculations, and displaying output. Functions and loops are used to implement logic in many programs.

Uploaded by

Sitaram Sds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

S No Name of the program Page No.

1
a)To evaluate algebraic exp(ax+b)/(ax-b)
b)to Evaluate algebraic exp 2.5logx+cos32+|xx-!!|+s"rt(2x!)
c)to evaluate t#e algebraic exp aepo$er-rt
%)to evaluate algebraic exp x po$er5 +1& x po$er '+( x po$er3+'x+2
1&
12
1'
1)
2 To evaluate area o* tria+gle (s"rt(s(s-a)(s-b)(s-c) 1(
3 To s$ap 2 +o 2&
' ,reatest o* 2 +o 22
5 ,reatest o* 3 +u-bers 2'
5 ,reatest o* 3 o+to pri+t t#e give+ +o i+ asce+%i+g or%er 2.
) To per*or- t#e arit#-etic expressio+ usi+g s$itc# state-e+t 3&
. /actorial o* give+ +o usi+g %o $#ile state-e+t 32
( To pri+t pri-e up to + +o 35
0 1u- o* + +atural +o 3(
1& Total +o. o* eve+ i+tegers '&
11 Total +o. o* o%% i+tegers '3
12 1u- o* eve+ i+tegers ')
13 1u- o* o%% i+tegers '.
1' 2 progra- to pri+t t#e pro%uct o* t$o -atrices o* a+! or%er 5&
15 3rite a progra- to pri+t /ibo+acci series 53
1) 3rite a progra- to pri+t o/ps
a) 1 b) 1 c) 1 %) 1
2 2 2 2 2 2 2 3
3 3 3 3 3 3 3 3 3 ' 5 )
5)
1. 3rite a progra- to rea% + +u- o* stu%e+ts a+% 5 sub -ar4s )(
1( 3rite a progra- to *i+% *actorial o* a +u- usi+g 3 t!pes o* *u+s .1
10 3rite a progra- to co+vert all lo$er case to uppercase c#aracters. .)
2& 3rite a progra- to extract a stri+g .0
21 3rite a progra- to sort 5 cit! +a-es i+ alp#abetical or%er (2
22 3rite a progra- to *i+% t#e *actorial o* a +u-ber usi+g recursio+ (5
23 2 progra- to pri+t a%%ress o* variable ((
2' 2 progra- to access a variable usi+g poi+ters 03
25 2 progra- to pri+t t#e ele-e+t o* arra! usi+g poi+ters 05
2) 2 progra- to i-ple-e+t call b! re*ere+ce 0.
2. 2 progra- to *i+% greatest o* 5+6 +u- usi+g *u+s 1&&
2( 2 progra- to pri+t t#e ele-e+ts o* a structure usi+g poi+ters 1&3
20 2 progra- to %ispla! stu%e+t i+*or-atio+ b! i+itiali7i+g structures 1&)
3& 2 progra- to *i+% total +u-ber o* -ar4s 1&(
S No Name of the program Page No.
31 2 progra- to *i+% t#e tot salar! o* e-plo!ee a+% salar! o* e-plo!ee
%etails
112
32 2 progra- to pass structure as a+ argu-e+ts to *u+ a+% cal total -ar4s o* 5
sub8ects
11)
33 2 progra- to %ispla! college a%%ress usi+g poi+ters a+% structures 11(
3' 2 progra- to $rite %ata *ile a+% rea% %ata *ro- *ile 12&
35 2 progra- to $rite i+teger %ata i+to *ile a+% rea% it *ro- *ile 123
3) 2 progra- to $rite pro%uct %etails 12)
3. 9se o* co--a+% li+e argu-e+ts i+ *iles 120
3( 1tac4 operatio+s usi+g arra!s 132
30 :ircular "ueue operatio+s usi+g arra!s 13.
'& ;+*ix-post*ix operatio+s 1'3
'1 Post*ix evaluatio+ 1')
'2 Pre*ix-evaluatio+ 1'0
'3 1i+gle li+4e% list 155
'' <ouble li+4e% lists 1)&
'5 =ubble 1ort 1)0
') 1electio+ 1ort 1.1
'. ;+sertio+ 1ort 1.'
'( >uic4 1ort 1.)
'0 ?eap 1ort 1.0
5& =i+ar! 1earc# 1(2
51 @i+ear 1earc# 1('
Experiment 1:
a)To evaluate algebraic exp(ax+b)/(ax-b)
b)to Evaluate algebraic exp 2!logx+co"#2+$x%x-&%&$+"'rt(2%x%&)
c)to evaluate the algebraic exp aepo(er-rt
))to evaluate algebraic exp x po(er! +1* x po(er ++, x po(er#++x+2
(a)
1) -./: To evaluate algebraic exp(ax+b)/(ax-b)
2) -0123.T4/:
1tep1A start
1tep2A i+put aBbBxBs
1tep3A sC (ax+b)/(ax-b)
1tep'A Desult s
1tep 5A stop
#) 5026 74-3T:
To evaluate algebraic exp (ax+b)/ (ax-b)
start
a=5,b=4,x=3
R=(ax+b)/(ax-b)
display
take a,b,x
stop
+) 83213-/:
To evaluate algebraic exp(ax+b)/(ax-b)
-ai+()
E
i+t aBbBxF
*loat sF
clrscr()F
pri+t*(Ge+ter t#e values o* aBbBx...G)F
sca+*(GH%H%H%GBIaBIbBIx)F
sC(ax+b)/(ax-b)F
pri+t*(Gt#e value o* sCH*GBs)F
J
!) 3e"ult:
Enter the value" of a9b9x: 1 # 2
The value of ";!
(b)
1) -./: To Evaluate algebraic exp 2!logx+co"#2+$x%x-&%&$+"'rt (2%x%&)
2) -0123.T4/:
1tep1A start
1tep2A i+put xB!Bv
1tep3A vC2.5log(x)+cos(323.1'/1(&)+-o%(xx-!!)+s"rt(2x!)
1tep'A Desult v
1tep 5A stop
#) 502674-3T:
To Evaluate algebraic exp 2!logx+co"#2+$x%x-&%&$+"'rt(2%x%&)
start
x=1,y=1
R=2.5*logx+os32+!od(x*x-y*y)+s"rt(2*x*y)
#isplay R
take x,y
stop
+) 83213-/:
To Evaluate algebraic exp 2!logx+co"#2+$x%x-&%&$+"'rt(2%x%&)
Ki+clu%eL-at#.#M
-ai+()
E
*loat xB!BvF
clrscr()F
pri+t*(Ge+ter x a+% ! valuesG)F
sca+*(GH*BH*GBIxBI!)F
vC2.5log(x)+(cos(323.1'/1(&))+-o%(xx-!!)+s"rt(2x!)F
pri+t*(Gt#e value o* vCH*GBv)F
J
5) DesultA
E+ter x a+% ! values
1&
2&
T#e value o* vC
c)
1) -./: To evaluate algebraic exp x po(er! +1* x po(er ++, x po(er#++x+2
2) -0123.T4/:
1tep1A start
1tep2A i+put xBs
1tep3AsCpo$(xBs)+1&po$(xB')+(po$(xB3)+'x+2
1tep'A Desult s
1tep 5A stop/
#) 502674-3T:
To evaluate algebraic exp x po(er! +1* x po(er ++, x po(er#++x+2
start
x=$
R==po%(x,s)+1&*po%(x,4)+'*po%(x,3)+4*x+2
#isplay R
take x
stop
+) 83213-/:
To evaluate algebraic exp x po(er! +1* x po(er ++, x po(er#++x+2
Ki+clu%eLst%io.#M
Ki+clu%eL-at#.#M
-ai+ ()
E
*loat xBsF
pri+t*(Ge+ter t#e values o* xG)F
sca+*(GH*GBIx)F
sCpo$(xB5)+1&po$(xB')+(po$(xB3)+'x+2F
pri+t*(Gt#e value o* sCH*GBs)F
J
!) 3e"ult:
E+ter t#e values o* x
1
T#e value o* s C 25
))
1) -./: To evaluate the algebraic exp ae po(er-rt
2) -0123.T4/:
step1A ta4e aB4 a+% t
step2A assig+ values *or t#e-
step3A #ere apo$(eB-4t) store t#is i+ NrN
<ispla! NrN
step'A stop/
#) 502674-3T:
To evaluate the algebraic exp a epo(er-rt
start
aC1B4C1BtC1
DCapo$(eB-4t)
%ispla!D
ta4e aB4Bt
stop
83213-/:
To evaluate the algebraic exp aepo(er-rt
Ki+clu%eLst%io.#M
Ki+clu%eL-at#.#M
-ai+()
E
i+t aB4BtF
*loat rF
pri+t*(Ge+tert#ree valuesG)F
sca+*(GH%H%H%GBIaBI4BIt)F
rCapo$(eB-4t)F
pri+t*(GresultCH*G)F
getc#()F
J
!) 3e"ult:
E+ter values
1
2
3
DesultC1.&&&&&&
<) =ue"tion":
i) 3#at is a+ Expressio+O
ii) 3#at is t#e use o* -ai+( ) *u+ctio+O
iii) 3#at are preprocessors o* :O
iv) 3#at is a variableO
>) ?ebugging:
1) u+%e*i+e% s!-bol 5a6 i+ *u+ctio+ -ai+( ) /irst !ou s#oul% %eclare 5a6 a+% use
2) 5r6 is assig+e% a value $#ic# is +ever
use%
3#e+ !ou assig+e% a value to a variableB
t#at -ust be use% i+ t#e progra-
3) re%eclaratio+ o* 5c6 i+ *u+ctio+ -ai+( ) Pou s#oul% %eclare a+! variable o+l! o+e
ti-e
Experiment 2: evaluate area of triangle ("'rt("("-a)("-b)("-c)
1) -./: To evaluate area of triangle ("'rt("("-a)("-b)("-c)
2) -0123.T4/:
1tep1Astart
1tep2Ai+put aBrBtBs
1tep3AsCa po$(-rt)
1tep'ADesult s
1tep 5Astop/
#) 502674-3T:
To evaluate area of triangle ("'rt("("-a)("-b)("-c)
(tart
a=5,b=4,=2
s=(a+b+)/2
)=s"rt(s-a)(s-b)(s-)
take a,b,,s,a
(top
#isplay R
+) 83213-/:
To evaluate area of triangle ("'rt("("-a)("-b)("-c)
Ki+clu%eL-at#.#M
voi% -ai+()
E
i+t aBbBcF
*loat sBareaF
clrscr()F
pri+t*(Ge+ter t#e values o* aBbBcG)F
sca+*(GH%H%H%GBIaBIbBIc)F
sC(a+b+c)/2F
areaCs"rt(s(s-a)(s-b)(s-c))F
pri+t*(Gt#e area o* a tra+gle is CH*GBarea)F
getc#()F
J
5) DesultA
e+ter t#e values o* aBbBc
1&
2&
3&
T#e area o* a tra+gle is C &.&&&&&&
)) >uestio+sA
i) 3#at is t#e use o* s"rt( ) *u+ctio+O
ii) Explai+ %ata t!pes.
iii) Explai+ ;/Q 1tate-e+ts.
>) ?ebugging:
1) /u+ctio+ 5s"rt( )6 s#oul% #ave a
protot!pe
Pou s#oul% i+clu%e 5-at#.#6 *irstB t#e+ !ou
ca+ use 5s"rt ( )6 a+% ot#er -at#e-atical
*u+ctio+s.
2) 9+ter-i+ate% stri+g or c#aracter
co+sta+t
Pou s#oul% e+% %ouble "uotatio+ or si+gle
"uotatio+ properl!
3) /u+ctio+ call -issi+g 5)6 i+ *u+ctio+
-ai+
Pou -ig#t be -isse% a+! special c#aracters
i+ t#at li+e.
Experiment #: S(apping given t(o number"
1) -./: 8rogram to "(ap t(o number"
2) -0123.T4/:
1tep1Astart
1tep2Ai+put aBb
1tep3AaCa+b
1tep'AbCa-b
1tep 5AaCa-b
1tep)ADesult aBb
1tep.Astop
#) 502674-3T:
8rogram to "(ap t(o number"
a=1,b=1&
a=a+b*b=a-b*a=a-b
#isplay a a+d b
take a,b
stop
start
+) 83213-/:
8rogram to "(ap t(o number"
voi% -ai+()
E
i+t aBbF
clrscr()F
pri+t*(Ge+ter t#e values o* aBbG)F
sca+*(GH%H%GBIaBIb)F
aCa+bF
bCa-bF
aCa-bF
pri+t*(Gt#e values o* aBb areA H% H%GBaBb)F
getc#()F
J
!) 3e"ult:
E+ter t#e values o* aBb
1&
2
T#e values o* aBb areA 2& 1&
<) =ue"tion":
i) 3#at is t#e use o* getc#( ) *u+ctio+O
ii) 3#at is t#e use o* speci*icatio+s o* t#e %ata t!pesO
Experiment +: 5in) greate"t number in given t(o number" u"ing
con)itional operator
1) -./: 8rogram to fin) greate"t of 2 number" u"ing con)itional operator
2) -0123.T4/:
1tep1Astart
1tep2Ai+put aBbBc
1tep3AcC(aMb)OaAb
1tep'ADesult c
1tep 5Astop/
#) 502674-3T:
To 5in) 1reate"t of T(o number"
(tart
,ake a,b
-= (a.b)/ a0b
#isplay
(top
+) 83213-/:
8rog:To fin) greate"t of 2 number"
voi% -ai+()
E
i+t aBbBcF
clrscr()F
pri+t*(Ge+ter t#e values o* aBbG)F
sca+*(GH%H%GBIaBIb)F
cC(aMb)OaAbF
pri+t*(Gt#e biggest +o is H%GBc)F
getc#()F
J
!) 3e"ult:
E+ter t#e values o* aBb
5
(
T#e biggest +u-ber is A (
<) =ue"tion":
1) 3#at is a+ operatorsO
2) ?o$ -a+! operators are t#ere i+ : a+% @ist out t#e-O
3) 3#at is t#e %i**ere+ce bet$ee+ logical a+% co+%itio+al operatorsO
Experiment !: 6rite a program to fin) greate"t among # number"
1) -./: 8rogram to fin) greate"t among # number"
2) -0123.T4/:
1tep1Astart
1tep2Ai+put aBbBc
1tep3Ai*(aMb) II(aMc)
1tep'A%ispla! a is grater
1tep 5Aelse
1tep)Ai*(bMc)
1tep.A %ispla! b is grater
1tep (Aelse
1tepA %ispla! c is grater
1tep1&Astop
#) 502674-3T:
To fin) greate"t among # number"
#isplay a
#isplay b
(tart
,ake a,b,
12
(a.b)33(a.
)
12 (b.)
#isplay
(top
+) 83213-/:
8rogram to fin) greate"t among # number"
voi% -ai+()
E
i+t aBbBcF
clrscr()F
pri+t*(Ge+ter t#e values o* aBb a+% cG)F
sca+*(GH%H%H%GBIaBIbBIc)F
i*(aMb II aMc)
pri+t*(Ga is greatest o* H% H% H%GB aBbBc)F
else
i*(bMc)
pri+t*(Gb is greatest o* H% H% H%GBaBbBc)F
else
pri+t*(Gc is gratest o* H% H% H%GBaBbBc)F
getc#()F
J
!) 3e"ult:
E+ter t#e values o* aBb a+% c
1&
3&
2&
3& is greatest o* 1& 3& 2&
<) =ue"tion":
i) 3#at are t#e co+%itio+al state-e+tsO
ii) ?o$ -a+! co+%itio+al state-e+ts are t#ere i+ :O
iii) 3#at is t#e %i**ere+ce bet$ee+ co+%itio+al a+% -ulti-co+%itio+al state-e+tsO
Experiment !: 8rogram to fin) 1reate"t of # number" to print the
given no in a"cen)ing or)er
1) -./: 8rogram to fin) 1reate"t of # number" to print the given no in
a"cen)ing or)er
2) -0123.T4/:
1tep1Astart
1tep2Ai+put aBbBc
1tep3Ai*(aMb) II(aMc)
1tep'Ai*(bMc)
1tep5A%ispla! aBbBc
1tep)Aelse
1tep.A%ispla! aBcBb
1tep(Aelse i*(bLc II bLa)
1tep0Ai*(cLa)
1tep1&Apri+t bBcBa
1tep11Aelse
1tep12Apri+t bBaBc
1tep13Aelse i*(cLa II cLb)
1tep1'Ai*(aLb)
1tep15Apri+t cBaBb
1tep1)Aelse
1tep1.Apri+t cBbBa
1tep1(Astop/
#) 502674-3T:
To 5in) greate"t of Three no to print the given no in a"cen)ing or)er
#isplay a,,b
(tart
,ake
a,b,
12
(a.b 33 a.)
12 (b.)
#isplay
a,b,
12
(b4
33(b4a)
12
(4
a)
#isplay b,,a #isplay b,a,
12
-4a 33
4b)
12
( a4b)
#isplay ,a,b
#isplay ,b,a
(top
+) 83213-/:
8rogram to fin) 1rate"t of # number" to print the given no in a"cen)ing or)er
voi% -ai+()
E
i+t aBbBcF
clrscr()F
pri+t*(Ge+ter t#e values o* aBb a+% cG)F
sca+*(GH%H%H%GBIaBIbBIc)F
i*(aLb II aLc)
E
i*(bLc)
E
pri+t*(G H%H%H%GB aBbBc)F
J
else
i*(bMc)
pri+t*(G H%H%H%GBaBcBb)F
J
else
i*(bLc II bLa)
E
i*(cLa)
pri+t*(G H%H%H%GBbBcBa)F
else
pri+t*(GH%H%H%GBbBaBc)F
J
else
i*(bLa)
pri+t*(GH%H%H%GBcBbBa)F
else
pri+t*(H%H%H%GBcBaBb)F
J
J
5) DesultA
E+ter t#e values o* aBb a+% c
)
'
5
' 5 )
Experiment <: 6rite a 8rogram to perform the arithmetic
expre""ion u"ing "(itch "tatement
1) -./: 8rogram to perform the arithmetic expre""ion u"ing "(itch
"tatement
2) -0123.T4/:
1tep1Astart
1tep2Ai+put aBb
1tep3As$itc#(result)
1tep'Acase 5+6Apri+t+u- o* aI b is a+b
1tep5A case 5-6Apri+t+u- o* aI b is a-b
1tep)A case 56Apri+t+u- o* aI b is ab
1tep.A case 5/6Apri+t+u- o* aI b is a/b
1tep(A case 5H6Apri+t+u- o* aI b is aHb
1tep0A %e*aultA i+vali% optio+
1tep1&A stop
#) 83213-/:
8rogram to perform the arithmetic expre""ion u"ing "(itch "tatement
Ki+clu%eLst%io.#M
Ki+clu%eLco+io.#M
voi% -ai+()
E
i+t aBbF
i+t opF
clrscr()F
pri+t*(G 1.a%%itio+R+ 2.subtractio+R+ 3.-ultiplicatio+R+ '.%ivisio+R+G)F
pri+t*(Ge+ter t#e values o* a I bG)F
sca+*(GH%H%GBIaBIb)F
pri+t*(Ge+ter !our c#oice A G)F
sca+*(GH%GBIop)F
s$itc#(op)
E
case 1 Apri+t*(Gsu- o* H% a+% H%CH%GBaBbBa+b)F
brea4F
case 2 Apri+t*(G%i**ere+ce o* H% a+% H%CH%GBaBbBa-b)F
brea4F
case 3 Apri+t*(G-ultiplicatio+ o* H% a+% H%CH%GBaBbBab)F
brea4F
case ' Apri+t*(G<ivisio++ o* t$o +u-bers is H%CGBa/b)F
brea4F
%e*ault A pri+t*(G E+ter Pour :orrect :#oice.G)F
brea4F
J
getc#()F
J
!) 3e"ult:
1. 2%%itio+
2. 1ubstractio+
3. Sultiplicatio+
'. <ivisio+
E+ter !our c#oice A 1
E+ter a a+% b values 1& 2&
1u- o* 1& a+% 2& C 3&
Experiment >: 6rite a program 8rogram to fin) the factorial of
a given number
1) -./: 8rogram to fin) the factorial of a given number
2) -0123.T4/:
1tep1A start
1tep2A i+put +B;B*
1tep3A *CiC1
1tep'A i*(iLC+)
1tep5A *C*i
1tep)A iCi+1
1tep.A repeat *ro- step5 to step) till steps true
1tep(A pri+t *
tep0A stop
#) 502674-3T:
8rogram to fin) the factorial of a given number
(tart
,ake +
2=2*i* i=i+1
#isplay 2
(top
5=i=1
12
(i4=+
)
+) 83213-/:
8rogram to fin) the factorial of a given number
voi% -ai+()
E
i+t +BiB*F
*CiC1F
clrscr()F
pri+t*(Ge+ter a +u-berG)F
sca+*(GH%GBI+)F
$#ile(iLC+)
E
*CiF
i++F
J
pri+t*(Gt#e *actorial o* H% is H%GB+B*)F
getc#()F
J
!) 3e"ult:
E+ter a +u-ber 5
T#e *actorial o* 5 is 12&
<) =ue"tion"@
i) 3#at are t#e @oops (;terative 1tate-e+ts)O
ii) 3#at are t#e <i**ere+ces bet$ee+ $#ile( ) a+% %o..$#ile( )O
iii) Explai+ about *or( ) loop.
Experiment ,: 6rite a program to generate all prime number" up to nth
number
1) -./: 8rogram to generate prime number till nth number
2) -0123.T4/:
1tep1A start
1tep2A rea% + value
1tep3A *or iC1 iLC+
1tep'Arepeat a b c % e
a)*actorial e"ual to &
b) *or iC1B8LC1 repeat cB%
c)i* i perce+tage 8 e"ual to 7ero
%) *act e"ual to *actorial a%%e% $it# o+e
e) i* *actorial e"ual to2pri+t as pri-e +u-ber
step5A %ispla! t#e pri-e +o till +t# +u-
)A stop
#) 502674-3T:
8rogram to generate prime number till nth number
(tart
,ake +,i,6
i=1,
i2 i4+
6=1, 2at=&
12
64=+
7ri+t i, 6++
12 i86=&
12
2at=2
7ri+t i
(top
+) 83213-/:
8rogram to generate prime number till nth number
voi% -ai+()
E
i+t +BiB*actB8F
pri+t*(Ge+ter t#e ra+geG)F
sca+*(GH%GBI+)F
pri+t*(TPri-e +u-bers areR+U)F
*or(iC1FiLC+Fi++)
E
*actC&F
*or(8C1F8LC+F8++)
E
i*(iH8CC&)
*act++F
i*(*CC2)
pri+t*(GH% TBi)F
J
getc#()F
J
5) DesultA
E+ter t#e ra+ge 1&
Pri-e +u-bers are
3 5 .
Experiment A: 6rite a program to fin) total of fir"t n natural number"
1) -./: 8rogram to fin) "um of n natural number"
2) -lgorithm:
1tep1A start
1tep2A rea% +
1tep3A iC&Bsu-C&
1tep'A per*or- *ro- step 5 to step ) u+til iLC+
1tep5A i++
1tep)Asu-+CiF
1tep.A $rite su-
1tep(A stop
#) 5lo( chart:
/
T
stop
Read +
i=&*s9!=&
:;ile(i4=+)
(9!+=i
i++
:rite s9!
start
+) 8rogram:
Ki+clu%eLst%io.#M
Ki+clu%eLco+io.#M
-ai+()
E
i+t +BiC&Bsu-C&F
clrscr( )F
pri+t*(TE+ter @i-it A T)F
sca+*(TH%UBI+)F
$#ile(iLC+)
E
i++F
su-+CiF
J
pri+t*(T1u- o* H% +atural +u-bers C H%UB+Bsu-)F
getc#()F
J
!) 3e"ult:
E+ter @i-it A 1&
1u- o* 1& +atural +u-bers C 55
Experiment 1*: 8rogram to fin) total of even integer"
1) -./: 8rogram to fin) total of even integer"
2) -0123.T4/:
step1A start
step2A *or iC&FiL2&Fi++
i*(aViWH2CC&)
su-Csu-+aViWF
step3A stop
To *i+% total o* eve+ i+teger.
#) 502674-3T:
8rogram to fin) total of even integer"
(tart
,ake i, a<2&=,
s9!
i=&
12
i4=2&
(9!=s9!+a<i=,i++
12
()<i=
82==&)
#isplay (9!
(top
1++
+) 83213-/:
8rogram to fin) total of even integer"
Ki+clu%eLst%io.#M
-ai+()
E
i+t aV2&WBiBsu-C&F
pri+t*(Ge+ter5 i+tegrsG)F
*or(iC&FiL5Fi++)
sca+*(GH%GBIaViW)F
*or(iC&FiL5Fi++)
E
i*(aViWCC&)
su-Csu-+aViWF
J
pri+*(Gsu- CH%GBsu-)F
getc#()F
J
!) 3e"ult:
E+tger 5 i+tegers
2 ' ) ( 2
1u- C 22
Experiment 11: 8rogram to fin) total of o)) integer"
1) -./: 8rogram to fin) total of o)) integer"
2) -0123.T4/:
step1A start
step2A *or(iC&FiL2&Fi++)
E
i*(aViWH2CC1)
su-Csu-+aViWF
J
step3Astop
#) 502674-3T:
8rogram to fin) total of o)) integer"
(tart
,ake i, a<2&=,
s9!
i=&
12
i4=2&
(9!=s9!+a<i=,i++
12
()<i=
82==1)
#isplay (9!
(top
1++
+) 83213-/:
8rogram to fin) total of o)) integer"
Ki+clu%eLst%io.#M
-ai+()
E
i+t aV2&WBiBsu-C&F
pri+t*(Ge+ter 5 i+tegrsG)F
*or(iC&FiL5Fi++)
sca+*(GH%GBIaViW)F
*or(iC&FiL5Fi++)
E
i*(aViWCC1)
su-Csu-+aViWF
J
pri+*(Gsu- CH%GBsu-)F
getc#()F
J
E+ter 5 i+tegers
1 2 3 ' 5
1u-C0
Experiment 12: 8rogram to fin) "um of all even integer"
83213-/: 8rogram to fin) "um of all even integer"
voi% -ai+()
E
i+t iB+Bsu-F
su-C&F
clrscr()F
pri+t*(Ge+ter a+! +u-berG)F
sca+*(GH%GBI+)F
*or(iC2FiLC+Fi++)
E
i*(iH2CC&)
su-Csu-+iF
J
pri+t*(Gtotal +o o* eve+ i+teger is H%GBsu-)F
J
!) 3e"ult:
E+ter a+! +u-ber 1&
1u- C 3&
Experiment 1#: 8rogram to fin) "um of all o)) integer"
1) -./: 8rogram to fin) "um of all o)) integer"
2) -0123.T4/:
1tep1A start
1tep2A rea% ;B+
1tep3A su-C&BiC&
1tep'A i*(iLC+) t#e+ iCi+1 else goto 2
1tep5A i* (iH2XC&) t#e+ su-++
1tep)A pri+t su-
1tep.A stop
#) 502674-3T:
8rogram to fin) "um of all o)) integer"
(tart
,ake i, a<2&=,
s9!
i=&
12
i4=2&
(9!=s9!+a<i=,i++
12
()<i=
82==1)
#isplay (9!
(top
i++
+) 83213-/:
8rogram to fin) "um of all o)) integer"
voi% -ai+()
E
i+t iB+Bsu-F
su-C&F
clrscr()F
pri+t*(Ge+ter a+! +u-berG)F
sca+*(GH%GBI+)F
*or(iC1FiLC+Fi++)
E
i*(iH2XC&)
su-Csu-+iF
J
pri+t*(Gtotal +o o* eve+ i+teger is H%GBsu-)F
J
!) 3e"ult:
E+ter a+! +u-ber 1&
1u- C 25
Experiment 1+: 8rogram to print pro)uct of t(o matrice"
1) -./: 8rogram to print pro)uct of t(o matrice"
2) -0123.T4/:
1tep1A start
1tep2Area% ;B8B4BaV3WV3WBbV3WV2WBcV3WV2W
1tep3A rea% aV3WV3W I bV3WV2W
1tep 'AiC&B8C&B4C&
1tep5A i* iL3 t#e+ i++ else goto 1
1tep)A i* 8L3 t#e+ 8++ else goto 5
1tep.A i* 4L3 t#e+ 4++ else goto )
1tep(A cViWV8WCcViWV8W+aV4WV8WbViWV4W
1tep0A pri+t aViWV8WBbViWV8WBcViWV8W
1tep 1&A stop
#) 502674-3T:
8rogram to print pro)uct of t(o matrice"
(tart
1=&,6=&,k=&
12
i4=2&
i2
(i4+
,ake a<3=<3=,b<3=<3=,<3=
<3=,i,6,k
5or
(k=&*64k.k+
+)
-<i=<6==<i=<6=+a<k=<6=*b<i=<k=
#isplay <i=<6=
(top
i2
64+
k++
6++
i++
+) 83213-/:
8rogram to print pro)uct of t(o matrice"
Ki+clu%eLst%io.#M
voi% -ai+()
E
i+t iB8B4BaV3WV3WBbV3WV2WBcV3WV2WF
pri+t*(Ge+ter ele-e+ts o* -atrix aG)F
*or(iC&FiL3Fi++)
E
*or(8C&F8L3F8++)
sca+*(GH%GBIaViWV8W)F
J
pri+t*(Ge+ter ele-e+ts o* -atrix bG)F
*or(iC&FiL3Fi++)
E
*or(8C&F8L2F8++)
sca+*(GH%GBIbViWV8W)F
J
*or(iC&FiL3Fi++)
E
*or(8C&F8L3F8++)
E
cViWV8WC&F
*or(4C&F4L3F4++)
E
cViWV8WCcViWV8W+aViWV4WbV4WV8WF
pri+t*(GRtH%GBcViWV8W)F
J
pri+t*(GR+G)F
J
J
J
J
5) DesultA
E+ter t#e ele-e+ts o* -atrix a
1 2 ' 5 2 1 ' 5 2
E+ter t#e ele-e+ts o* -atrix b
1 2 ' 5 2 1 ' 5 2
1& 1( 2(
5& 1( .
'& '5 1'
Experiment 1!: 8rogram to print 5ibonacci "erie"
1) -./: 8rogram to print 5ibonacci "erie"
2) -0123.T4/:
1tep1A start
1tep2A rea% ;BxB*B*1B*2
1tep3A *C&B*1C1B*2C1
1tep'A %o
;++
/1C*2
/2C*
/C*1+*2
3#ile (iLC+)
1tep5A pri+t *
1tep)A stop
#) 502674-3T:
8rogram to print 5ibonacci "erie"
(tart
,ake 1, x, 2, 21, 22
5=&, 21=1, 22=1
:;ile
(i4=+)
1++,51=22*22=2
5=2+22
5=2+22
#isplay 5
(top
+) 83213-/:
8rogram to print 5ibonacci "erie"
voi% -ai+()
E
i+t iB+B*B*1B*2F
pri+t*(Ge+ter t#e ra+geG)F
sca+*(GH%GBI+)F
*C&F
*1C1F
*2C1F
%o
E
i++F
pri+t*(GH%R+GB*)F
*1C*2F
*2C*F
*C*1+*2F
J
$#ile(iLC+)F
J
5) DesultA
E+ter t#e ra+ge 0
& 1 1 2 3 5 ( 13 21
Experiment 1< : 8rint the 5ollo(ing format"
1).1)1 1).2 ) 1 1).3 ) 1 1).') 1
2 2 2 2 2 2 2 3
3 3 3 3 3 3 3 3 ' 5 )
1) -./: program to print the follo(ing format
1
1 2
2 # #
# + + +
2) -0123.T4/:
step1Astart
step2Ata4e ;B8 a+% +
step3A*or(iC1FiL+Fi++)
*or(8C&F8LiF8++)
E
pri+t*(UH%UBi)F
pri+t*(UR+U)F
J
step'A stop
#) 502674-3T:
8rogram to print the follo(ing format
1
2 2
# # #
+ + + +
(tart
,ake 1,6,+,i=1,6=1
12
i4+
12
64+
#isplay i
#isplay >?+@
(top
A++
1++
+) 83213-/:
8rogram to print the follo(ing format
1
2 2
# # #
+ + + +
Ki+clu%eLst%io.#M
-ai+()
E
i+t iB8B+F
pri+t*(Te+ter + valueU)F
sca+*(TH%UBI+)F
*or(iC&FiLC+Fi++)
E
*or(8C&F8LiF8++)
pri+t*(UH%UBi)F
pri+t*(UR+U)F
J
pri+t*(UR+U)F
J
5) DesultA
1
2 2
3 3 3
' ' ' '
Experiment 1<2 :
1) -./: 8rogram to print the follo(ing format
2) -0123.T4/:
1
2 2
# # #
+ + + +
step1A start
step2A ta4e t#ree i+tegers iB8B+
step3A repeat step' to step) *or iC1BiLC+Bi++
step'A repeat step5 *or 8C1B8LC+B8++
step5A i* 8MC1 t#e+
<ispla! ; a+% a space
Else
<ispla! space
step)A tra+s*er cursor to -eet li+e b! pri+ti+g 5R+6
step.A stop
#) 502674-3T:
8rogram to print the follo(ing format
1
2 2
# # #
+ + + +
+) 83213-/:
8rogram to print the follo(ing format
1
2 2
# # #
+ + + +
Ki+clu%eLst%io.#M
(tart
,ake i,6,+
5or
(i=1*i4=+*i+
+)
12
(6.i)
#isplay i #isplay >?+@
(top
#isplay >?t@
#isplay >?+@
1++
-ai+()
E
i+t iB8C&B+F
pri+t*(Te+ter + valueU)F
sca+*(TH%UBI+)F
*or(iC&FiLC+Fi++)
E
i*(8MCi)
pri+t*(UH%RtUBi)F
else
pri+t*(UR+U)F
J
pri+t*(URtU)F
J
pri+t*(TR+U)F
J
5) DesultA
1
2 2
# # #
+ + + +
Experiment 1<# :
1) -./: 8rogram to print the follo(ing format
2) -0123.T4/:
1
2 2
# # #
step1A start
step2A ta4e t#ree i+tegers iB8B4
step3A repeat step2 to step( *or iC1BiLC+Bi++
step'A repeat step3 to step' *or 4C1B4LC+-iB4++
step5A %ispla! bla+4 space
step)A repeat step 5 to step. *or 8C1B8LC;B8++
step.A %ispla! bla+4 space
step(A ta4e cursor to +e$ li+e
step0A stop
#) 502674-3T:
8rogram to print the follo(ing format
1
2 2
# # #
(tart
,ake i,6,+,k=&,6=1
12
14+
#isplay@?+@
#isplay >?+@
B4+
;*
YLCi
#isplay i
(top
A++
1++
+) 83213-/:
8rogram to print the follo(ing format
1
2 2
# # #
Ki+clu%eLst%io.#M
-ai+()
E
i+t iB8B4B+F
pri+t*(Te+ter + valueU)F
sca+*(TH%UBI+)F
*or(iC&FiLC+Fi++)
E
*or(4C&F4LC+-iF4++)
E
pri+t*(U U)F
J
*or(8C1F8LCiF8++)
E
pri+t*(U U)F
pri+t*(U iU)F
J
J
5) DesultA
1
2 2
# # #
Experiment 1<+ :
1) -./: 8rogram to print the follo(ing format
2) -0123.T4/:
1
2 #
+ ! <
step1A start
step2A ta4e t#ree i+tegers iB8B4B+ a+% i+itiali7e 4 as 1
step3A repeat step' to step. *or iC1BiLC+Bi++
step'A repeat step5 to step) *or 8C1B8LCiB8++
step5A %ispla! value o* 4
step)A i+cre-e+t 4 b! 1
step.A tra+s*er cursor to +ext li+e b! pri+ti+g 5R+6
step(A stop
502674-3T:
8rogram to print the follo(ing format
1
2 #
+ ! <
(tart
,ake 1=&,6=&,k
B=&
12
14=+
i2
64=+
B=k+1
#isplay B
#isplay >?+@
(top
A++
1++
83213-/:
8rogram to print the follo(ing format
1
2 #
+ ! <
Ki+clu%eLst%io.#M
-ai+()
E
i+t iB8B4C1B+F
pri+t*(Te+ter + valueU)F
sca+*(TH%UBI+)F
*or(iC&FiLC+Fi++)
E
*or(8C&F8LCiF8++)
pri+t*(UH%RtUB4++)F
pri+t*(UR+ U)F
J
J
5) DesultA
1
2 #
+ ! <
Experiment 1>: program to rea) num of "tu)ent )ata
1) -./: program to rea) num of "tu)ent )ata
2) -0123.T4/:
step1A ta4e a c#aracter arra! aB i+tegers rBsB;B8 a+% +
step2A rea% t#e value o* +
step3A *or(iC&FiL+Fi++)
E+ter roll+oB+a-eBBBBBB
Dea% t#ese a+% e+ter 5 sub8ect -ar4s
sViWV5WC&F
*or(8C&F8L5F8++)
E
sca+*(TH%UBsViWV8W)F
sViWV5WCsViWV5W+sViWV8WF
J
step'A%ispla! +ViWBrViWBsViWV8W
step5Astop
#) 502674-3T:
8rogram to rea) num of "tu)ent )ata: (tart
,ake +<2&=
<2&=,r<2&=,s<2&=,1=&,6,+
12
14+
Read Ca!e, RollCo
Read 5 (9b6ets Darks
1++
12
14+
1=&
#isplay +<i=, r<i=
12
14+
A=&
#isplay s<i=<6=
A++
(top
+) 83213-/:
8rogram to rea) num of "tu)ent )ata
Ki+clu%eLst%io.#M
Ki+clu%eLco+io.#M
voi% -ai+()
E
c#ar +V2&WV1&WF
i+t iB8BrV2&WBsV2&WV)WF
pri+t*(Ge+ter + valueG)F
sca+*(GH%GBI+)F
*or(iC&FiL+Fi++)
E
pri+t*(Ge+ter +a-eBroll+oB....G)F
sca+*(GHsH%GBI+ViWBIrViW)F
pri+t*(Ge+ter 5 sub8ect -ar4sG)F
sViWV5WC&F
*or(8C&F8L5F8++)
E
sca+*(GH%GBsViWV8W)F
sViWV5WCsViWV5W+sViWV8WF
J
J
pri+t*(Gt#e %ata e+tere% is R+G)F
*or(iC&FiL+Fi++)
E
pri+t*(GHsRtH%RtGB+ViWBrViW)F
*or(8C&F8L5F8++)
pri+t*(GH%RtGBsViWV8W)F
J
getc#()F
J
5) DesultA
E+ter +a-eBroll+oBZ.Es$ar 2&
E+ter 5 sub8ect -ar4s
1& 5& 3' &) '2
T#e %ata e+tere% is
Es$ar 2& 1& 5& 3' &) '2
Experiment 1,1 :
Experiment: 3rite a progra- to *i+% *actorial o* a +u- usi+g 3 t!pes o* *u+cto+s
1) -./: 8rogram to fin) factorial of a given number
2) -0123.T4/:
"tep1:"tart
1tep2Ata4e a +u-ber +
1tep3Area% a +u-ber +
/or(iC&FiL+Fi++)
/actorialC*act;F
<ispla! +u-
1tep'Astop
#) 502674-3T:
8rogram to fin) factorial of a given number:
(tart
,ake +
2=2*i* i=i+1
#isplay 2
(top
5=i=1
12
(i4=+
)
+) 83213-/:
8rogram to fin) factorial of a given number
Ki+clu%eLst%io.#M
Ki+clu%eL-at#.#M
voi% -ai+()
E
clrscr()F
pri+t*(Ge+ter a +u-berG)F
*act()F
getc#()F
J
*act()
E
i+t iB*actC1B+F
sca+*(GH%GBI+)F
*or(iC1FiLC+Fi++)
E
*actC*actiF
J
pri+t*(GR+*actorial o* a give+ +o isA H% GB*act)F
retur+ *actF
J
!) 3e"ult:
E+ter a +u-ber 5
/actorial o* a give+ +o isA 12&
Experiment 1,2 :
1) -./: 8rogram to fin) factorial of a given number
2) -0123.T4/:
step1A start
1tep2A ta4e a +u-ber ; a+% *actC1
1tep3A rea% a +u-ber +
/or(iC&FiL+Fi++)
/actorialC*actiF
<ispla! *act
1tep'A stop
#) 502674-3T:
program to fin) factorial of a given number
(tart
,ake +
2=2*i* i=i+1
#isplay 2
(top
5=i=1
12
(i4=+
)
59+tio+ 5at(+) -alli+g
5at(+)
+) 83213-/:
program to fin) factorial of a given number
Ki+clu%eLst%io.#M
Ki+clu%eL-at#.#M
voi% -ai+()
E
clrscr()F
pri+t*(Ge+ter a +u-berG)F
*act()F
getc#()F
J
*act()
E
i+t iB*actC1B+F
sca+*(GH%GBI+)F
*or(iC1FiLC+Fi++)
E
*actC*actiF
J
pri+t*(GR+*actorial o* a give+ +o isA H% GB*act)F
retur+ *actF
J
!) 3e"ult:
E+ter a +u-ber 5
/actorial o* a give+ +o isA 12&
Experiment 1A : 6rite a program to convert all lo(er ca"e to upperca"e
character"
1) -./: 8rogram on function to "can a character "tring an) convert lo(er ca"e
character to upper ca"e
2) -0123.T4/:
step1A start
1tep2A ta4e a stri+g a *u+ctio+ o* retur+ value %ata t!pe is voi% str upper
1tep3A rea% a stri+g
3#ile (sViWX C6R&6)
E
i*((sViWMC6a6) II(sViWLC676))
sViWCsViW-32F
i++F
J
%ispla! c#a+ge% stri+g.
1tep'A stop
#) 502674-3T:
8rogram on function to "can a character "tring an) convert lo(er ca"e character to
upper ca"e
(tart
,ake str,1,6,
:;ile
(<i=E=F?&F
12
(((<i=.=FaF)
33 (s<i=.=FGF))
(<i==s<i=-32
1++
(top
+) 83213-/:
8rogram on function to "can a character "tring an) convert lo(er ca"e character to
upper ca"e
Ki+clu%eLst%io.#M
Ki+clu%eLco+io.#M
voi% -ai+()
E
c#ar strF
pri+t*(Ge+ter a stri+gG)F
sca+*(GHsGBstr)F
to[str[upper(c#arVW)F
pri+t*(Gc#a+ge% to HsGBstr)F
J
voi% to[str[upper(c#arVW)
E
i+t iC&F
$#ile(sViWXCNR&N)
E
i*((sViWMCNaN) II (sViWMCN7N))
sViWCsViW-32F
i++F
J
J
J
!) 3e"ult:
E+ter a stri+g
g+ec
c#a+ge% to ,NE:
Experiment 2*: 3rite a progra- to extract a stri+g
1) -./: - program to extract a portion of character "tring an) print extracte)
"tring
2) -0123.T4/:
step1A start
1tep2A ta4e a a a+% r c#aracters arra!s a+% ;B8B-B+ be u+tegers
1tep3A e+ter t#e values o* -B+
YC&F
/or(iC+-1FiL-++-1Fi++)
E
rV8WCsViWF
8++F
J
step'A %ispla! t#e extract part o* stri+g
1tep5Astop
#) 502674-3T:
- program to extract a portion of character "tring an) print extracte) "tring
(tart
,ake
s<3&=,r<3&=,6=&,+
12
14!++!-
1
1=+-1
rV8WCsViW
A++
1++
(top
+) 83213-/:
8rogram to extract a portion of character "tring an) print extracte) "tring
Ki+clu%eLst%io.#M
voi% -ai+()
E
c#ar sV3&WBrV3&WF
i+t iB8B-B+F
clrscr()F
pri+t*(Ge+ter a stri+gG)F
gets(s)F
pri+t*(Ge+ter t#e values o* - +G)F
sca+*(GH%H%GBI-BI+)F
8C&F
*or(iC+-1FiL-++-1Fi++)
E
rV8WCsViWF
8++F
J
pri+t*(Gt#e extract part o* stri+g HsA GBr)F
getc#()F
J
!) 3e"ult:
E+ter a stri+g
,uru+a+a4
E+ter t#e values o* -B+
3 5
T#e extract part o* stri+gA ru+
Experiment 21: 3rite a progra- to sort 5 cit! +a-es i+ alp#abetical or%er
1) -./: 8rogram to rea) five citie" an) "ort them an) print "orte) li"t of citie) in
alphabetical or)er
2) -0123.T4/:
step1Astart
1tep2Ae+ter 5 cit! +a-es
1tep3Ata4e ; a+% 8 loop variables
/or(iC)5FiL122Fi++)
E
*or(8C&F8L5F8++)
E
i*(cit!V8WV&WCCi)
pri+t*(UR+HsUBcit!V8W)F
J
J
1tep'Astop
502674-3T:
- program to rea) five citie" an) "ort them an)
8rint "orte) li"t of citie) in alphabetical or)er
+) 83213-/:
- program to rea) five citie" an) "ort them an) print "orte) li"t of citie) in
alphabetical or)er
Ki+clu%eLst%io.#M
Ki+clu%eLco+io.#M
voi% -ai+()
E
(tart
,ake ity<5=<2&=, 1,6
1=&
12
(i45)
i2
14122
A=&
i2
645
12
(-ity<6=
<&===i)
#isplay ity<6=
A++=
1++
H+ter -ity Ca!es
1++
(top
c# cit!V5WV2&WF
i+t ;B8F
clrscr()F
pri+t*(Ge+ter t#e +a-es o* cities...R+R+G)F
*or(iC&FiL5Fi++)
sca+*(GHsGBIcit!ViW)F
pri+t*(Gsorte% list o* cities...R+R+G)F
*or(iC)5FiL122Fi++)
E
*or(8C&F8L5F8++)
E
i*(cit!V8WV&WCCi)
pri+t*(GR+HsGBcit!V8W)F
J
J
J
5) DesultA
E+ter t#e +a-es o* cities
?!% :#e++ai =o-ba! goa vi7ag
1orte% list o* cities
=o-ba!
:#e++ai
,oa
?!%
vi7ag
Experiment 22: 6rite a program to fin) the factorial of a number u"ing
recur"ion
1) -./: 8rogram to fin) the factorial of a number u"ing recur"ion
2) -0123.T4/:
step1A start
1tep2A e+ter * a+% +
1tep3A rea% a +u-ber +
/C*actorial (+)F
1tep'A i+si%e t#e *u+ctio+al(x) %e*i+e a local variable 5x6
;*(xCCl)
Detur+ (l)F
Else
/actCx*actorial(x-l)F
Detur+(*act)F
1tep5A stop
#) 502674-3T:
To fin) the factorial of a number u"ing recur"ion
(tart
,ake +
2=2*i* i=i+1
#isplay 2
(top
5=i=1
12
(i4=+
)
59+tio+ 5at(+) -alli+g
5at(+)
+) 83213-/:
To fin) the factorial of a number u"ing recur"ion
Ki+clu%eLst%io.#M
-ai+()
E
i+t *B+F
clrscr()F
pri+t*(Ge+ter +G)F
sca+*(GH%GBI+)F
*C*actorial(+)F
pri+t*(GH%GB*)F
getc#()F
J
*actorial(x)
E
i+t iB*actC1F
i*(xCC1)
retur+(1)F
else
*actCx*actorial(x-1)F
retur+(*act)F
J
!) 3e"ult:
E+ter + '
2'
Experiment 2#: program to print a))re"" of a variable
1) -im: program to print a))re"" of a variable
2) -lgorithm:
1tep1A start
1tep2A %eclare a
1tep3A pri+t Ia
1tep'A stop
#) 5lo(chart:
start
#elare a
7ri+t 3a
stop
+) 8rogram:
Ki+clu%eLst%io.#M
Ki+clu%eLco+io.#M
-ai+( )
E
i+t aF
clrscr()F
pri+t*(T2%%ress o* a C HuTBIa)F
getc#()F
J
!) 3e"ult:
2%%ress o* a C)''53
Experiment 2+: program to illu"trate acce""ing the value of variable u"ing
pointer" u"ing arithmetic operation"
1) -./: program to illu"trate acce""ing the value of variable u"ing pointer"
u"ing arithmetic operation"
2) -0123.T4/:
step1A start
step2A ta4e aBbBxB!B7 a+% t$o poi+ters variables p1Bp2
step3A assig+ values to t#ese variables
p1CIaF
p2CIbF
xCp1p2-)F
!C('-p2)/(p1+1&)F
%ispla! x a+% !
step'Ap2Cp2+3
p1Cp2-5F
7Cp1p2-)F
%ispla! aBb a+% 7
step5A stop
#) 502674-3T:
- program to illu"trate acce""ing the value of variable u"ing pointer" u"ing
arithmetic operation"
(tart
a=12,b=4
71=3a,p2=3b
I=*p1*p2-$
J=(4-*p2)/*p1+1&
#isplay p1,p2,a,b,x,y
*p2=*p2+3,*p1=*p2-5
K=*p1*p2-$
#isplay a,b,G
(top
+) 83213-/:
- program to illu"trate acce""ing the value of variable u"ing pointer" u"ing
arithmetic operation"
Ki+clu%eLst%io.#M
-ai+()
E
i+t aBbBp1Bp2BxB!B7F
clrscr()F
aC12BbC'F
p1CIaF p2CIbF
xCp1p2-)F
!C('-p2)p1+1&F
pri+t*(Ga%%resso* aCH%R+GBp1)F
pri+t*(Ga%%resso* bCH%R+GBp2)F
pri+t*(GaCH%BbCH%R+GBaBb)F
pri+t*(GxCH%B!CH%R+GBxB!)F
p2Cp2+3F p1Cp2-5F
7Cp1p2-)F
pri+t*(GaCH%BbCH%R+GBaBb)F
pri+t*(G7CH%R+GB7)F
getc#()F
J
!) 3e"ult:
2%%ress o* a C )55'3
2%%ress o* b C )''55
a C 12 b C '
7C'2
Experiment 2+: - program to acce"" a variable u"ing pointer"
1) -./: 8rogram to illu"trate the a))re"" of a variable u"ing variou"
metho)"
2) -0123.T4/:
step1A start
step2A ta4e xBpB" a+% a c#aracter a
step3A %ispla! aBxBpB"
step5A stop
#) 502674-3T:
- program to illu"trate the a))re"" of a variable u"ing variou" metho)"
+) 83213-/:
- program to illu"trate the a))re"" of a variable u"ing variou" meth)"
(tart
a=FaF,x=125,p=1&.25
, "=1'.L$
#isplay a, 3a
#isplay x, 3x
#isplay p, 3p
#isplay ", 3"
K=*p1*p2-$
(top
Ki+clu%eLst%io.#M
-ai+()
E
c#ar aF
i+t xF
*loat pB"F
clrscr()F
aCNaNF
xC125F
pC1&.25B"C1(..)F
pri+t*(GHc is store% at a%%ress HuR+GBaBIa)F
pri+t*(GH% is store% at a%%ress HuR+GBxBIx)F
pri+t*(GH* is store% at a%%ress HuR+GBpBIp)F
pri+t*(GH* is store% at a%%ress HuR+GB"BI")F
getc#()F
J
!) 3e"ult:
a i" "tore) at a))re"" <!!2!
12! i" "tore) at a))re"" <!!22
1*2!**** i" "tore) at a))re"" <!!1,
1,><**** i" "tore) at a))re"" <!!1+
Experiment 2!: 8rogram to print the element" of arra& u"ing pointer"
1) -./: 8rogram to print the element" of arra& u"ing pointer"
2) -0123.T4/:
step1A start
step2A ta4e a+ arra! a o* 5 ele-e+tsa+% a poi+ter p
step3A pri+t all t#e el-e+ts o* arra!
step5A stop
#) 502674-3T:
- program to print the element" of arra& u"ing pointer"
+) 83213-/:
8rogram to print the element" of arra& u"ing pointer"
Ki+clu%eLst%io.#M
-ai+()
E
i+t aV5WCE5B'B)B(B0JF
i+t pCIaV&WF
i+t iF
clrscr()F
*or(iC&FiL5Fi++)
pri+t*(GH%GB(p+i))F
*or(iC&FiL5Fi++)
pri+t*(G HuR+GB(p+i))F
getc#()F
J
(tart
,ake a<5==M5,4,$,',NO, *p=3a<&=, i=&
12
145
#isplay *(p+i)
#isplay (p+i)
1++
(top
!) 3e"ult:
1 2 3 ' 5
1 2 3 ' 5
Experiment 2<: 8rogram to implement call b& reference"
1) -./: 8rogram to implement call b& reference"
2) -0123.T4/:
step1A start
step2A ta4e aB bB c
step3A ta4e a%%itio+ as a *u+ctio+ a+% store t#e a%%ress o* a a+% b as *u+ctio+ a+%
store t#e a%%ress o* a a+% b as argu-e+ts i+ it
step5A ta4e x a+% ! as *or-al variables store i+ 7
step)A retur+ 7
step.A stop
#) 502674-3T:
- program to implement call b& reference"
+) 83213-/:
- program to implement call b& refer"
Ki+clu%eLst%io.#M
(tart
,ake a=1&,b=2&
-=add (3a,3b)
K=*x+*y
Ret9r+ (G)
)dd (i+t *x,i+t *y)
#isplay
(top
-ai+()
E
i+t aC1&BbC2&BcF
clrscr()F
cCa%%(IaBIb)F
pri+t*(GH%GBc)F
getc#()F
J
a%%(i+t xBi+t !)
E
i+t 7F
7Cx+!F
retur+(7)F
J
!) 3e"ult:
3&
Experiment 2>: 8rogram to fin) greate"t of number" function" an) pointer"
1) -./: 8rogram to fin) greate"t of number" function" an) pointer"
2) -0123.T4/:
step1A start
step2A ta4e a+ arra! aV2&W a+%t#ree i+tegers cB+BgxBpB" a+% a c#aracter a
step3A accept value o* + *ro- t#e user %ispla! aBxBpB"
step5A repeat step ' *or iC&BiL+Bi++
step)A accept value *or user a+% store at a+i
step.A goto step a I se+% a a+% + as argu-e+ts
step(A %ispla! value retur+ *ro- step2
step0A stop
#) 502674-3T:
- program to fin) greate"t of number" function" an) pointer"
(tart
,ake a<1&=,i=&,+,l
1=o
Dax=*(arr+i)
#isplay P
P=!ax(a,+)
Read a+1
12
14+
1++
Dax(i+t *arr,i+t s)
(top
12
14+
12
(i==&QQ
(arr+i)
1++
Ret9r+ (!ax)
+) 83213-/:
- program to fin) greate"t of number" function" an) pointer"
Ki+clu%eLst%io.#M
-ai+()
E
i+t aV2&WBiB+BlF
clrscr()F
pri+t*(Ge+tert#e +o.o*ele-e+tsA G)F
sca+*(GH%GBI+)F
*or(iC&FiL+Fi++)
sca+*(GH%GBIaViW)F
lC-ax(aB+)F
pri+t*(Gt#e largest +u- isA H%GBl)F
getc#()F
J
i+t -ax(i+tarrBi+t s)
E
i+t -axBiF
*or(iC&FiLFi++)
i*(iCC&||-axL(arr+i))
-axC(arr+i)F
retur+ (-ax)F
J
!) 3e"ult:
E+ter +u-ber o* ele-e+ts 3
5 ) '
T#e largest +u-ber is )
#isplay (p+i)
Experiment 2,: - program to print the element" of a "tructure u"ing pointer"
1) -./: 8rogram to print the element" of a "tructure u"ing pointer"
2) -0123.T4/:
step1A start
step2A ta4e a c#aracter arra! +a-eB a +u-ber a+% price i+ structure
step3A i+ -ai+ ta4e a struct variable pro%uct a+% a poi+ter
*or(ptrCpro%uctFptrLpro%uct+3Fptr++)
rea% t#e value b! usi+g arra! operator
ptr-M+a-eBptr-M+oBptr-Mprice
step'A %ispla! +a-eB+oBprice
step5A stop
#) 502674-3T:
- program to print the element" of a "tructure u"ing pointer"
(tart
,ake prod9t<3=,*ptr
12
7tr4prod9t
+3
Read ptr-.+a!e, 3ptr-.+9!ber,
3ptr-.prie
7tr=prod9t
%;ile
7tr4prod9t
+3
#isplay ptr-.+a!e,7tr=.+9!ber,
ptr-.prie
7tr ++
(tart
+) 83213-/:
- program to print the element" of a "tructure u"ing pointer"
Ki+clu%eLst%io.#M
struct i+vest
Ec#ar +a-eV2&WF
i+t +u-berF
*loat priceFJF
-ai+()
E
struct i+vest pro%uctV3WBptrF
clrscr()F
pri+t*(Gi+putR+R+G)F
*or(ptrCpro%uctV3WFptrLpro%uct+3Fptr++)
sca+*(GHsH%H*GBptr-M+a-eBIptr-M+u-berBIptr-Mprice)F
pri+t*(GR+Desult R+R+G)F
ptrCpro%uctF
$#ile(ptrLpro%uct+3)
E
pri+t*(GH2&sH5%H1&.2*R+GBptr-M+a-eBptr-M+u-berBptr-Mprice)F
ptr++F
J
getc#()F
J
Experiment 2A: 8rogram to )i"pla& "tu)ent information b& initialiBing
"tructure"
-./: 8rogram to )i"pla& "tu)ent information b& initialiBing "tructure"
-0123.T4/:
step1A ta4e +a-eB roll +o a+% age i+si%e t#e stu%e+t structure
step2A e+ter t#e re"uire% %ata
step3A stop
502674-3T:
- program to )i"pla& "tu)ent information b& initialiBing "tructure"
83213-/:
- program to )i"pla& "tu)ent information b& initialiBing "tructure"
Ki+clu%eLst%io.#M
struct stu%e+t
E
(tart
,ake +a!e, Roll+o , age
(tr9t (t9de+t
#isplay +a!e, roll+o, age
(top
c#ar +a-eV1&WF
i+t roll+oF
i+t ageF
JF
-ai+()
E
static struct stu%e+t s1F
clrscr()F
pri+t*(Ge+ter t#e +a-eBroll+oBageG)F
sca+*(GHsH%H%R+GBIs1.+a-eBIs1.roll+oBIs1.age)F
pri+t*(GHs H% H%GBs1.+a-eBs1.roll+oBs1.age)F
getc#()F
J
!) 3e"ult:
Ente name9 rollno9age
3avi 11 2!
3avi 11 2!
Experiment #*: 8rogram to fin) the total no of marC"
-./: 8rogram to fin) the total no of marC"
-0123.T4/:
step1A ta4e +a-eB roll +o a+% total i+si%e t#e structure
step2A e+ter t#e -ar4s o* *ive sub8ects
*or(iC&FiL+Fi++)
pri+t*(Ge+ter sVH%W stu%e+t -ar4sG Bi)F
sViW.totalC&F
*or(8C&F8L5F8++)
rea% t#e value o* sViW.sub8ectV8W
sViW.totalCsViW.total+sViW.sub8ectV8WF
step3A %ispla! sViW.total
step'A stop
502674-3T:
- program to fin) the total no of marC"
83213-/:
- program to fin) the total no of marC"
Ki+clu%eLst%io.#M
struct stu%e+t
E
c#ar +a-eV1&WF
i+t roll+oF
i+t sub8ectV5WBtotalF
JF
-ai+ ( )
E
static struct stu%e+t sV1&&WF
i+t +BiB8F
clrscr()F
pri+t*(Ge+ter t#e +o.o* stu%e+tsG)F
sca+*(GH%GBI+)F
pri+t*(Ge+ter t#e -ar4s o* *ivesub8ectsG)F
*or(iC&FiL+Fi++)
E
pri+t*(Ge+ter sVH%W stu%e+t -ar4sGBi)F
sViW.totalC&F
*or(8C&F8L5F8++)
E
sca+*(GH%GBIsViW.sub8ectV8W)F
sViW.totalCsViW.total+sViW.sub8ectV8WF
J
pri+t*(GH%GBsViW.total)F
J
J
(tart
(tr9t st9de+t s
H+ter CR.o2 (t9de+ts
H+ter Darks o2 5iSe (9b6ets,
1=&
12
14+
(<i=.total=&
12
645
A=&
(<i==s<i=.total+s<i=.s9b6et<6=
A++
#isplay ,otal
1++
(tart
!) 3e"ult:
e+ter t#e +o.o* stu%e+ts2
e+ter t#e -ar4s o* *ivesub8ectse+ter sV&W stu%e+t -ar4s1
2
3
'
5
15e+ter sV1W stu%e+t -ar4s12
32
1'
15
)5
13(
Experiment #1: 8rogram to fin) the "alar& of emplo&ee an) "alar& )etail"
1) -./: 8rogram to fin) the "alar& of emplo&ee an) "alar& )etail"
2) -0123.T4/:
step1A ta4e a c#aracter arra! o* +a-eB a+ i% i+si%e t#e structure
step2A ta4e a+ot#er structure o* i+si%e t#e structure +a-e t#at salar! ta4eB basicB p*B
#raB %aB gross
step3A e+ter t#e +a-eB i% o* a+ e-plo!ee a+% rea% t#ese
step'A use %ot operator to access t#ese variables
step5A %ispla! gross salar!
step)A stop
#) 502674-3T:
- program to fin) the "alar& of emplo&ee an) "alar& )etail"
+) 83213-/:
- program to fin) the "alar& of emplo&ee an) "alar& )etail"
Ki+clu%eLst%io.#M
struct e-plo!ee
E
(tart
(tr9t e!ployee e1
(tr9t salary s1
H+ter +a!e ,id, salary
H1.s1.;ra=158*basi
H1.s1.da=458*basi
H1.s1.gross=e1.s1.basi+e1.s1.;ra
+e1.s1.da+e1.s1.p2
#isplay Tross (alary
#isplay Uasi
#isplay Vra
#isplay #)
#isplay 72
(top
c#ar +a-eV1&WF
i+t i%F
struct salar!
E
i+t basicBp*F
*loat #raBtaB%aBgrossF
Js1F
Je1F
-ai+()
E
pri+t*(Ge+ter +a-e I i% o* e-pG)F
sca+*(GHsH%GBIe1.+a-eBIe1.i%)F
pri+t*(Ge+ter salar! o* e-pG)F
sca+*(GH%H*H*H%GBIe1.s1.basicBIe1.s1.#raBIe1.s1.%aBIe1.s1.p*)F
e1.s1.#raC15H basicF
e1.s1.%aC'5HbasicF
e1.s1.grossCe1.s1.basic+e1.s1.#ra+e1.s1.%a+-e1.s1.p*F
pri+t*(GHsR+H%GBe1.+a-eBe1.s1.gross)F
pri+t*(GR+H%R+H*R+H%R+H*R+GBe1.s1.basicBe1.s1.#raBe1.s1.%aBe1.s1.p*Be1.s1.gross)F
J
!) 3e"ult:
E+ter +a-e a+% i% o* e-p
Es$ar
1&1
E+ter salar! o* E-p
5&&&
,ross salar! A (&&&
Experiment #2 : 8rogram to pa"" "tructure a" an argument to function
7alculate total marC"
1) -./: 8rogram to pa"" "tructure a" an argument to function 7alculate
total marC"
2) -0123.T4/:
step1A ta4e a structure ex2
step2A i+si%e t#e structure %eclare ) i+tegers
step3A %eclare structureex2 as s1
step'A %eclarestruture ex2 as s2Bex2 as *u+()F
step5A %ispla! t#e -essage e+ter t#e -ar4s
step)A ta4e value o* t#e sub8ects *ro- t#e user
step.A store t#e retur+ value i+ s2.total
step(A pri+t t#e value o* s2.total
step0A stop
#) 83213-/:
- program to pa"" "tructure a" argument" to function -n) calculate total
marC" of ! "tu)ent"
Ki+clu%eLst%io.#M
struct ex2
E
i+t -1B-2B-3B-'B-5BtotalF
JF
-ai+()
E
struct ex2 s1F
struct ex2 s2F
struct ex2 *u+()F
pri+t*(Ge+ter t#e -ar4sG)F
sca+*(GH%H%H%H%H%GBIs1.-1BIs1.-2BIs1.-3BIs1.-'BIs1.-5)F
s2C*u+(s3)F
pri+t*(GH%GBs1.total)F
J
struct ex2 *u+(s3)
struct ex2 s3F
E
s3.totalCs3.-1+s3.-2+s3.-3+s3.-'+s3.-5F
retur+(s3)F
J
+) 3e"ult:
E+ter t#e -ar4s
1& 2& 3& '& 5&
15&
Experiment ##: 8rogram to )i"pla& college a))re"" u"ing pointer" an)
"tructure"
1) -./: 8rogram to )i"pla& college a))re"" u"ing pointer" an) "tructure"
2) -0123.T4/:
step1A ta4e +a-eB locatio+ a+% cit! *or t#e college
step2A ta4e a poi+ter variable I a%%ress o* t#e college
step3A p-M+a-eCENNg+ecNNJ
p-Mlocatio+CEGibra#i-pat+a-GJ
p-Mcit!CEGrr %istGJ
step'A %ispla! p-M+a-eBp-Mlocatio+Bp-Mcit!
step5A stop
#) 83213-/:
- program to )i"pla& college a))re"" u"ing pointer" an) "tructure"
Ki+clu%eLst%io.#M
struct college a%%ress
E
c#ar +a-eV2&WBlocatio+V2&WBcit!V2&WF
JF
-ai+()
E
struct college a%%ress a%%BptrF
pCIa%%F
p-M+a-eCEGg+ecGJF
p-Mlocatio+CEGibra#i-pat+a-GJF
p-Mcit!CEGrr %istGJF
pri+t*(GHsHsHsGBp-M+a-eBp-Mlocatio+Bp-Mcit!)F
J
+) 3e"ult:
,+ec ibra#i-pat+a- rr %ist
Experiment #+: 8rogram to (rite )ata file an) rea) )ata from file
1) -./: 8rogram to (rite )ata file an) rea) )ata from file
2) -0123.T4/:
step1A start
step2A ta4e a c#aracter c# a+% %e*i+e a *ile poi+ter *2
step3A ope+ a *ile %ata.%at *or $riti+g
step'A $#ile ((c#Cgetc#()XCeo*)
rea% a c#aracter c#
step5A close t#e *ile %ata.%at
step)A ope+ t#e sa-e *ile *or rea%i+g
$#ile((c#Cget(*2)XCEQ/)
%ispla! c#arecter o+ -o+itor
step.A close t#e %ata.%at
step(Astop
#) 502674-3T:
8rogram" to (rite )ata file an) rea) )ata from file
(tart
51PH *22
Rpe+t #ara 2ile
to %erite
79t(;,22)
-lose (22)
:;ile
((-;==g
et;ar()
)E=HR5)
:;ile
((-;==
get())E
==HR5)
Rpe+ data 2ile to read
79t;ar (;, 22)
-lose (22)
(top
+) 83213-/:
- program to (rite )ata file an) rea) )ata from file
Ki+clu%eLst%io.#M
-ai+()
E
c#arc#F
/;@E *2F
*2C*ope+(G%ata.%atGBG$G)F
$#ile((c#Cgetc#ar())XCEQ/)
putc(c#B*2)F
*close(*2)F
*2C*ope+(G%ata.%atGBGrG)F
$#ile((c#Cgetc(*2))XCEQ/)
putc#ar(c#)F
*close(*2)F
J
Experiment #!: 8rogram to (rite integer )ata into file an) rea) it from
file
1) -./: 8rogram to (rite integer )ata into file an) rea) it from file
2) -0123.T4/:
step1A start
step2A ta4e a +u-ber a+% %e*i+e a *ile poi+ter
step3A ope+ a *ile %ata.%at *or $riti+g
step'A rea% o+ i+teger a+% also rea% a+i+ter i+to *ile
step5A close t#e *ile %ata.%at
step)A ope+ t#e sa-e *ile *or rea%i+g
%ispla! a+ i+teger
step.A stop
#) 502674-3T:
- program to (rite integer )ata into file an) rea) it from file
+) 83213-/:
(tart
51PH *22
Rpe+ #ata 2ile to
%rite
Read +9!
79t%( +9!,22)
-lose (22)
Rpe+ data 2ile to read
C9!=get%(22)
#isplay C9!
-lose (22)
(top
- program to (rite integer )ata into file an) rea) it from file
Ki+clu%eLst%io.#M
-ai+()
E
i+t +u-F
/;@E *2F
*2C*ope+(G%ata.i+tGBG$G)F
sca+*(GH%GBI+u-)F
put$(+u-B*2)F
*close(*2)F
*2C*ope+(G%ata.i+tGBGrG)F
+u-Cget$(*2)F
pri+t*(GH%GB+u-)F
*close(*2)F
J
!) 3e"ult:
12
12
Experiment #<: 8rogram to (rite pro)uct )etail"
1) -./: 8rogram to (rite pro)uct )etail"
2) -0123.T4/:
step1A start
step2A ta4e a c#arecter arra! c
step3A ta4e t#ree i+tegers pB"Bb
step'A %e*i+e a *ile poi+ter *p
step5A ope+ a *ile %ata.%at *or $riti+g
step)A accept c *ro- user a+% pB"
step.A $rite stri+g i+ c a+%values o*pB" i+to *ile
step(A close t#e *ile %ata.%at
step0A ope+ t#e sa-e *ile *or rea%i+g
step1&A evaluate p" a+% store i+ b
%ispla! cBpB"Bb to t#e user
step11A closet#e %ata.%at
step(Gstop
#) 83213-/:
- program to (rite pro)uct )etail"
Ki+clu%eLst%io.#M
-ai+()
E
c#ar cV2&WF
i+t pB"BbF
/;@E *2F
*2C*ope+(G%ata.%atGBG$G)F
pri+t*(Ge+ter ite- +a-eBpriceB"ualit!G)F
sca+*(GHsH%H%GBIcBIpBI")F
bCp"F
pri+t*(GHsH%H%H%GBcBpB"Bb)F
*close(*2)F
J
!) 3e"ult:
E+ter ite- +a-eB priceB "ualit!
Dice 25 1
Dice 25 1 25
50274-3T:
- program to (rite pro)uct )etail"
(tart
51PH *22
52=Rpe+ data 2ile to
%rite
H+ter +a!e,prie,"9ality
b=p*"
#isplay ,p,".b
-lose (22)
(top
Experiment #>: 8rogram to D"e comman) line argument" in file"
1) -./: 8rogram to D"e comman) line argument" in file"
2) -0123.T4/:
step1A start
step2A ta4e argcBargv i+ -ai+ *u+ctio+ a+ arra! o* $or% a+% i
step3A %e*i+e a *ile poi+ter
step'A ope+ a *ile co--a+%.%at *or $riti+g
*or(iC&FiLargcFi++)
<ispla! argvViW
close t#e *ile
step)Aope+ t#e sa-e *ile *or rea%i+g
*or(iC1FiMargcFi++)
%ispla! $or%
step.A close t#e *ile
step(A stop
#) 502674-3T:
8rogram to u"e comman) line
argument" in file"
+) 83213-/:
8rogram to u"e comman) line argument" in file"
Ki+clu%eLst%io.#M
-ai+(argcBargv)
E
c#ar $or%V1&WBargvVWF
i+t iBargcF
/;@E *2F
*2C*ope+(Gco--a+%.%atGBG$G)F
*or(iC1FiLargcFi++)
*pri+t*(*pBGHsGBargvViW)F
*close(*p)F
*2C*ope+(Gco--a+%.%atGBGrG)F
*or(iC1FiLargcFi++)
E
*sca+*(*pBGHsGB$or%)F
J
*close(*p)F
J
(tart
51PH *22
52=Rpe+ data 2ile to %rite
12
14arg
;C&
3rite to *ileB argvViW
:lose (*2)
52=Rpe+ 2ile to read data
12
14arg
;C&
Read data 2ro! 2ile
:lose (*2)
(top
Experiment #,: 8rogram to implement StacC operation" u"ing arra&"
1) -./: 8rogram to implement StacC operation" u"ing arra&"
2) -0123.T4/:
1. pus#(sBtopBx)A
step1A start
step2A(c#ec4 *or stac4 over*lo$)
i*(topMC-ax)
%ispla! Gstac4 over*lo$G
retur+
step3AVi+cre-e+t top poi+terW
top++
step'AVi+cre-e+t a+ ele-e+t i+ t#estac4W
sVtopW L- x
step5AV*i+is#e%W
retur+
2.pop(sBtop)
step1A(c#ec4 *or stac4 u+%er*lo$)
i*(topCC&)
%ispla!() Gstac4 u+%er*lo$G
step2AV%ecre-e+t top operatorW
topL- top-1
step3AV%elete a+ ele-e+t *ro- t#e stac4W
retur+
(sVtop+1W)
#) 83213-/:
StacC operation" u"ing arra&"
Ki+clu%eLst%io.#M
K%e*i+e -ax 1&
voi% pus#()F
voi% pop()F
voi% %ispla!()F
i+t sV-axWF
i+t topC&F
voi% -ai+()
E
c#ar c#F
i+t c#oiceF
%o
E
pri+t*(Ge+ter c#oice o* operatio+G)F
pri+t*(G1.pus#()B2.pop()B3.%ispla!()G)F
sca+*(GH%GBIc#oice)F
s$itc#(c#oice)
E
case1A
pus#()F
brea4F
case2A
pop()F
brea4F
case3A
%ispla!()F
brea4F
%e*aultA
pri+t*(Gi+vali% optio+G)F
J
pri+t*(G%o u $a+tto co+ti+ue !/+G)F
**lus#(st%i+)F
sca+*(GHcGBIc#)F
J
$#ile(c#CCN!N||c#CCN!N)
J
voi% pus#()
E
i+t ite-F
i*(topMC-ax)
pri+t*(Gstac4is*ullG)F
else
E
pri+t*(Ge+ter a+! ite-G)F
sca+*(GH%GBIite-)F
top++F
sVtopWCite-F
J
J
voi% pop()
E
i+t ite-F
i*(topCC&)
pri+t*(Gstac4 is e-pt!G)F
else
E
ite-CsVtopWF
pri+t*(Gt#e relate% ele-+t is H%GBite-)F
top--F
J
J
voi% %ispla!()
E
i+t ite-F
i+t iF
i*(topCC&)
pri+t*(GR+ stac4 is e-pt! +o ele-e+t is%ispla!e%G)F
else
E
pri+t*(GR+H%R+GBsViW)F
pri+t*(GR+----R+G)F
J
J
!) 3e"ult:
e+ter c#oice o* operatio+1.pus#()B2.pop()B3.%ispla!()1
e+ter a+! ite-3
%o u $a+tto co+ti+ue !/+!
e+ter c#oice o* operatio+1.pus#()B2.pop()B3.%ispla!()1
e+ter a+! ite-'
%o u $a+tto co+ti+ue !/+!
e+ter c#oice o* operatio+1.pus#()B2.pop()B3.%ispla!()3
1515&
----
%o u $a+tto co+ti+ue !/++
Experiment #A: 8rogram to implement =ueue operation" u"ing arra&"
1) -./: 8rogram to implement =ueue operation" u"ing arra&"
2) -0123.T4/:
step1Astart
step2A(resetrearpoi+ter)
i* rC+
t#e+ rL-1
else
rL-r+1
step3A(over*lo$)
i* *Cr
t#e+ $rite G"ueue over*lo$G
retur+
step'AVi+sert ele-e+tW
"VrWL-r
step5AVsett#e poi+terW
i* *C&
t#e+*L-1
retur+
a+ algorit#- *or %elete ele-e+t *ro- "ueue
step1AVu+%er*lo$W
i**C&
t#e+ $rite "ueue over*lo$
step2AV%elete ele-e+tW
!L-"(*)
step3AV"ueue e-pt!W
i* WL-rL-&
retur+(!)
step'AVi+cre-e+t *ro+t poi+terW
i* WC+
t#e+
*L-1
else
*L-*+1
retur+(!)
#) 83213-/:
8rogram to implement =ueue operation" u"ing arra&"
Ki+clu%eLst%io.#M
K%e*i+e -ax1&
voi% i+sert()F
voi% %elete()F
voi% %ispla!()F
i+t c"V-axWF
i+t *ro+tC&BrearC&F
voi% -ai+()
E
i+t c#oiceF
c#ar c#F
%o
E
pri+t*(Ge+ter c#oice *or circular "ueueG)F
pri+t*(G1-i+sert()
2-%elete()
3-%ispla!()G)F
sca+*(GH%GBIc#oice)F
s$itc#(c#oice)
E
case 1A
i+sert()F
brea4F
case 2A
%elete()F
brea4F
case 3A
%ispla!()F
brea4F
%e*aultA
pri+t*(Gi+vali% optio+G)F
brea4F
J
pri+t*(G%o u $a+tto co+ti+ue !/+G)F
**lus#(st%i+)F
sca+*(GHcGBIc#)F
J
$#ile(c#CCN!N||c#CCN!N)F
J
voi% i+sert()
E
i+t ite-F
i*(rearCC-ax)
rearC1F
else
error++F
i*(*ro+tCCrear)
pri+t*(G"ueue over*lo$G)F
else
E
pri+t*(Ge+ter a+! ite-G)F
sca+*(GH%GBIite-)F
c"VrearWCite-F
J
i*(*ro+tCC&)
*ro+tC1F
J
voi% %elete()
E
i+t ite-F
i*(*ro+tCC&)
pri+t*(G"ueue u+%er*lo$G)F
else
E
ite-Cc"V*ro+tWF
pri+t*(Gt#e %elete% ele-e+t i% H%GBite-)F
J
i*(*ro+tCCrear)
E
*ro+tC&F
rearC&F
retur+F
J
i*(*ro+tCC-ax)
*ro+tC1F
else
*ro+tC*ro+t+1F
J
voi% %ispal!()
E
i+t iF
i*(*ro+tCC&)
pri+t*(G+o ele-e+t i+t#e "ueueG)F
else
E
i*(*ro+tLrear)
*or(iC*ro+tFiLCrearFi++)
E
pri+t*(GH%GB"ViW)F
J
else
*or(iC*ro+tFiMrearFi--)
pri+t*(GH%GB"ViW)F
J
J
!) 3e"ult:
1) ;+sert 2) <elete 3) <ispla!
E+ter c#oice *or circular "ueue 1
E+ter a+! ite- 1'
1) ;+sert 2) <elete 3) <ispla!
E+ter c#oice *or circular "ueue 1
E+ter a+! ite- 15
1) ;+sert 2) <elete 3) <ispla!
E+ter c#oice *or circular "ueue 1
E+ter a+! ite- 2&
1) ;+sert 2) <elete 3) <ispla!
E+ter c#oice *or circular "ueue 3
1' 15 2&
Experiment +*: 8rogram infix-po"tfix operation
1) -./: 8rogram infix-po"tfix operation
2) 83213-/ +#:
Ki+clu%eLst%io.#M
Ki+clu%eLco+io.#M
K%e*i+e S2\ 1&&
voi% pus#(c#ar)F
c#ar pop()F
i+t topC-1F
c#ar stac4VS2\WF
voi% -ai+()
E
c#ar 2Bi+*ixV1&&WBpostV1&&WBxBc#F
i+t iB8C&F
clrscr()F
pri+t*(GE+ter t#e ;+*ix expressio+.....R+G)F
gets(i+*ix)F
pus#(N(N)F
*or(iC&F(xCi+*ixViW)XCNR&NFi++)
E
c#CN)NF
i*((xMCN2N)II(xLCN]N))
postV8++WCxF
else
i*(xCCN(N)
pus#(x)F
else
i*(xCCN)N)
E
$#ile(c#XCN(N)
E
c#Cpop()F
postV8++WCc#F
J
8--F
J
else
E
$#ile(prec(x)LCprec(stac4VtopW))
E
c#Cpop()F
postV8++WCc#F
J
pus#(x)F
J
J
postV8WCNR&NF
pri+t*(GT#e Post*ix Expressio+ is.....R+G)F
puts(post)F
getc#()F
J
i+t prec(c#ar !)
E
i+t 4F
s$itc#(!)
E
case N+NA4C1F
brea4F
case N-NA4C1F
brea4F
case NNA4C2F
brea4F
case N/NA4C2F
brea4F
case N^NA4C3F
brea4F
case N(NA4C&F
brea4F
J
retur+(4)F
J
voi% pus#(c#ar ite-)
E
i*(topCCS2\)
E
pri+t*(GQver/lo$G)F
retur+F
J
else
E
topCtop+1F
stac4VtopWCite-F
J
retur+F
J
c#ar pop(c#ar ite-)
E
i*(topCC-1)
E
pri+t*(G9+%er*lo$G)F
retur+F
J
else
E
ite-Cstac4VtopWF
topCtop-1F
retur+ ite-F
J
J
+) 3e"ult:
E+ter t#e ;+*ix Expressio+A((2+=)(:-<)/((E+/)(,-?)
T#e Expecte% QutPut is...2=:<E/,?/+-+-
T#e Post*ix Expressio+ isA2=+:<-E/+,?-
Experiment +1: 8rogram to implement 8o"tfix evaluation
1) -./: 8rogram to implement 8o"tfix evaluation
2) 83213-/:
8rogram to implement 8o"tfix evaluation
Ki+clu%eLco+io.#M
K%e*i+e S2\ 1&&
voi% pus#(i+t)F
i+t pop()F
i+t topC-1B*C&BiF
i+t stac4VS2\WF
voi% -ai+()
E
c#ar postV1&&WBxF
i+t valueB aBbF
clrscr()F
pri+t*(GE+ter t#e Post*ix Expressio+....G)F
gets(post)F
*or( iC&F(xCpostViW)XCNR&NFi++)
E
i*(is%igit(x))
E
pus#(x-N&N)F
J
else
E
aCpop()F
bCpop()F
valueCper*or-(xBaBb)F
pus#(value)F
J
J
gets(post)F
*or(iC&F(xCpostViW)XCNR&NFi++)
E
i*(is%igit(x))
E
pus#(xC&)F
J
else
E
aCpop()F
bCpop()F
valueCper*or-(xBaBb)F
pus#(value)F
J
J
pri+t*(GT#e value o* t#e post*ix expressio+ is AH%R+GBstac4VtopW)F
getc#()F
J
i+t per*or-(c#ar !Bi+t -B i+t +)
E
i+t 4F
s$itc#(!)
E
case N+NA4C++-F
brea4F
case N-NA4C+--F
brea4F
case NNA4C+-F
brea4F
case N/NA4C+/-F
brea4F
case N^NA4Cpo$(+B-)F
brea4F
J
retur+(4)F
J
voi% pus#(i+t ite-)
E
i*(topCCS2\)
E
pri+t*(Gover*lo$R+G)F
retur+F
J
else
E
topCtop+1F
stac4VtopWCite-F
J
retur+F
J
i+t pop(i+t ite-)
E
i*(topCC-1)
E
pri+t*(Gu+%er*lo$R+G)F
retur+F
J
else
E
ite-Cstac4VtopWF

topCtop-1F
retur+ ite-F
J
J
#) 3e"ult: 1
1.E+ter t#e Post*ix expressio+ )5'+
T#e value o* t#e Post*ix expressi+ isA 2)
3e"ult: 2
2.E+ter t#e Post*ix expressio+ is )5(0+-
T#e vlaue o* t#e Post*ix expressio+ isA -.2 /
Experiment +2: 8rogram to implement 8refix evaluation
1) -./: 8rogram to implement 8refix evaluation
2) -0123.T4/:
step1Ai+itiali7estac4 to be e-pt!
reverse give+ i/p stri+g
step2Asca+ *ro- le*t to rig#t i* t#e i/p stri+g is opera+% pus# it o+ to t#e stac4
step3Ai* t#e i/p stri+g is operator t#e+ t#e *irst t$o operatoro+ t#e stac4
areevaluate%
usi+g t#is operator b! poppi+g t#e- *ro- t#e stac4 a+% t#e result is also palce% o+
t#estac4
#) 83213-/:
8rogram to implement 8refix evaluation
Ki+clu%eLst%io.#M
Ki+clu%eLco+io.#M
i+t stV1&&WF
i+t st[topC-1F
i+t cal(c#ar postVW)F
voi% i+[post(c#ar i+VW)F
voi% pus#[ite-(i+t it)F
i+t pop[ite-()F
i+t st[;1P(c#ar t)F
i+t st[;:P(c#ar t)F
/-ai+ *u+ctio+/
voi% -ai+()
E
c#ar i+V1&&WBpostV1&&WF
clrscr()F
pri+t*(GR+RtE+ter t#e ;+*ix Expressio+A G)F
gets(i+)F
i+[post(i+)F
getc#()F
J
/e+% -ai+/
voi% pus#[ite-(i+t it)
E
i*(st[topCC00)
E
pri+t*(GR+R+Rt1T2:_ is /ullG)F
getc#()F
exit(1)F
J
stV++st[topWCitF
J
i+t pop[ite-()
E
i+t itF
i*(st[topCC-1)
E
getc#()F
J
retur+(stVst[top--W)F
J
//u+ctio+ *or co+verti+g a+ i+*ix expressio+ to a post*ix expressio+. /
voi% i+[post(c#ar i+VW)
E
i+t xC&B!C&B7BresultC&F
c#ar aBcB postV1&&WF
c#ar tF
pus#[ite-(NR&N)F
tCi+VxWF
$#ile(tXCNR&N)
E
i*(isal+u-(t))
//or c#ec4i+g $#et#er t#e value i+ t is a+ alp#abet or +u-ber. /
E
postV!WCtF
!++F
J
else i*(tCCN(N)
E
pus#[ite-(N(N)F
J
else i*(tCCN)N)
E
$#ile(stVst[topWXCN(N)
E
cCpop[ite-()F
postV!WCcF
!++F
J
cCpop[ite-()F
J
else
E
$#ile(st[;1P(stVst[topW)MCst[;:P(t))
E
cCpop[ite-()F
postV!WCcF
!++F
J
pus#[ite-(t)F
J
x++F
tCi+VxWF
J
$#ile(st[topXC-1)
E
cCpop[ite-()F
postV!WCcF
!++F
J
pri+t*(GR+RtT#e Post*ix Expressio+ isAG)F

*or(7C&F7L!F7++)
pri+t*(GHcGBpostV7W)F
pri+t*(GR+R+<o !ou $a+t to evaluate t#e Desult o* Post*ix Expressio+O(P/N)AG)F
sca+*(GHcGBIa)F
i*(aCCN!N || aCCNPN)
E
resultCcal(post)F
pri+t*(GR+R+RtDesult isA H%R+GBresult)F
getc#()F
J
else i*(aCCN+N || aCCNNN)
E
exit(&)F
J
J
/<eter-i+i+g priorit! o* i+si%e ele-e+ts/
i+t st[;1P(c#ar t)
E
s$itc#(t)
E
case N(NAretur+ (1&)F
case N)NAretur+ (0)F
case N+NAretur+ (.)F
case N-NAretur+ (.)F
case NNAretur+ (()F
case N/NAretur+ (()F
case NR&NAretur+ (&)F
%e*aultA pri+t*(GExpressio+ is i+vali%.G)F
brea4F
J
retur+ &F
J
/<eter-i+i+g priorit! o* approac#i+g ele-e+ts/
i+t st[;:P(c#ar t)
E
s$itc#(t)
E
case N(NAretur+ (1&)F
case N)NAretur+ (0)F
case N+NAretur+ (.)F
case N-NAretur+ (.)F
case NNAretur+ (()F
case N/NAretur+ (()F
case NR&NAretur+ (&)F
%e*aultA pri+t*(GExpressio+ is i+vali%.G)F
brea4F
J
retur+ &F
J/Evaluati+g t#e result o* post*ix expressio+/
i+t cal(c#ar postVW)
E
i+t -B+BxB!B8C&Ble+F
le+Cstrle+(post)F
$#ile(8Lle+)
E
i*(is%igit(postV8W))
E
xCpostV8W-N&NF
pus#[ite-(x)F
J
else
E
-Cpop[ite-()F
+Cpop[ite-()F
s$itc#(postV8W)
E
case N+NAxC++-F
brea4F
case N-NAxC+--F
brea4F
case NNAxC+-F
brea4F
case N/NAxC+/-F
brea4F
J
pus#[ite-(x)F
J
8++F
J
i*(st[topM&)
E
pri+t*(GNu-ber o* Qpera+%s are -ore t#a+ Qperators.G)F
exit(&)F
J
else
E
!Cpop[ite-()F
retur+ (!)F
J
retur+ &FJ
+) 3e"ult:
E+ter t#e ;+*ix Expressio+A a+bc
T#e Post*ix Expressio+ isA abc+
<o !ou $a+t to evaluate t#e Desult o* Post*ix Expressio+O(P/N)A
Experiment +#: 8rogram to implement Single linCe) li"t
-./: 8rogram to implement Single linCe) li"t
83213-/:
8rogram to implement Single linCe) li"t
Ki+clu%eLst%io.#M
K%e*i+e +ull &
struct li+4e%-list
E
i+t +u-berF
struct li+4e%-list +extF
JF
t!pe%e* struct li+4e%-list +o%eF
-ai+()
E
i+t c#F
+o%e #ea%F
voi% create(+o%e p)F
i+t cou+t(+o%e p)F
voi% pri+t(+o%e p)F
+o%e i+sert(+o%e p)F
+o%e *i+%(+o%e pBi+t 4e!)F
+o%e %elete(+o%e #ra%)F
#ea%C(+o%e )-alloc(si7eo*(+o%e))F
create(#ea%)F
pri+t*(GR+G)F
pri+t(#ea%)F
pri+t*(GR+G)F
pri+t*(GR+ +u-o* ite-sCH%GBcou+t(#ea%))F
pri+t*(Ge+ter1-i+sertB2-%eleteG)F
pri+t(list-M+ext)F
J
retur+F
J
i+t cou+t(+o%e list)
E
i*(list-M+extCC+ull)
retur+(&)F
else
retur+(1+cou+t(list-M+ext))F
J
+o%e i+sert(+o%e #ea%)
E
+o%e *i+%(+o%e pBi+t a)F
+o%e +e$B+1F
i+t 4e!BxF
pri+t*(Ge+ter value o* +e$ ite-R+G)F
sca+*(GH%GBIx)F
pri+t*(Gvalue o* 4e! ite- be*ore $#ic# ite- is i+serte%O-000 i* it is lostG)F
sca+*(GH%GBI4e!)F
i*(#ea%-M+u-berCC4e!)
E
+e$C(+o%e)-alloc(si7eo*(+o%e))F
+e$-M+u-berCxF
+e$-M+extC#ea%F
#ea%C+e$F
J
else
E
+1C*i+%(#ea%B4e!)F
i*(+1CC+ull)
pri+t*(G4e! is +ot *ou+%G)F
else
E
+e$C(+o%e)-alloc(si7eo*(+o%e))F
+e$-M+u-berCxF
+e$-M+extC+1-M+extF
+1-M+extC+e$F
J
J
retur+(#ea%)F
J
+o%e *i+%(+o%e listBi+t 4e!)
E
i*(list-M+ext-M+u-berCC4e!)
retur+(list)F
else
i*(list-M+ext-M+extCC+ull)
retur+(+ull)F
else
*i+%(list-M+extB4e!)F
J
+o%e %elete(+o%e #ea%)
E
+o%e *i+%(+o%e pBi+t a)F
i+t 4e!F
+o%e +1BpF
pri+t*(Ge+ter t#e +u- to be %elete%G)F
sca+*(GH%GBI4e!)F
i*(#ea%-M+u-berCC4e!)
E
pC#ea%-M+extF
*ree(#ea%)F
#ea%CpF
J
else
E
+1C*i+%(#ea%B4e!)F
i*(+1CC+ull)
pri+t*(GR+4e! +ot *ou+%G)F
else
E
pC+1-M+ext-M+extF
*ree(+1-M+ext)F
+1-M+extCpF
J
J
retur+(#ea%)F
J
!) 3e"ult:
1) ;+sert 2) <elete 3) <ispla!
E+ter c#oice *or circular "ueue 1
E+ter a+! ite- 1'
1) ;+sert 2) <elete 3) <ispla!
E+ter c#oice *or circular "ueue 1
E+ter a+! ite- 15
1) ;+sert 2) <elete 3) <ispla!
E+ter c#oice *or circular "ueue 1
E+ter a+! ite- 2&
1) ;+sert 2) <elete 3) <ispla!
E+ter c#oice *or circular "ueue 3
1' 15 2&
Experiment ++: 8rogram to implement ?ouble linCe) li"t
1) -./: 8rogram to implement ?ouble linCe) li"t
2) 83213-/:
8rogram to implement ?ouble linCe) li"t
Ki+clu%eLst%io.#M
struct +o%e
E
i+t i+*oF
struct +o%e lptrBrptrF
JF
struct +o%e curre+tB#ra%C+ullF
-ai+()
E
c#arc#CN!NF
i+t c#oiceF
voi% create()F
voi% %elete()F
voi% i+sert()F
voi% traverse()F
pri+t*(Gcreatio+ o* %oubleli+4e%listG)F
%oE
J
create()F
pri+t*(G%o u $a+tto co+ti+ue a+ot#er +o%e(!/+))F
**lus#(st%i+)F
sca+*(GHcGBIc#)F
J
$#ile(c#XCN+N)F
c#CN!NF
pri+t*(G1.traverseR+G)F
pri+t*(G2.i+sertR+G)F
pri+t*(G3.%eleteR+G)F
$#ile(c#CCN!N)
E
pri+t*(Ge+ter u rc#oiceR+G)F
sca+*(GH%GBIc#oice)F
s$itc#(c#oice)
E
case1Apri+t*(Gt#e ele-e+t i+ t#e list areR+G)F
traverse()F
brea4F
case2Ai+sert()F
brea4F
case3A%elete()F
brea4F
Jsca+*(GHcGBIc#)F
J
J
voi%create()
E
i+t +oF
struct +o%e te-pF
pri+t*(Ge+ter t#e +u- R+G)F
sca+*(GH%GBI+o)F
te-pC(struct +o%e)-alloc(si7eo*(struct(+o%e))F
te-p-MlptrC+ullF
te-p-Mi+*oC+oF
te-p-MrptrC+ullF
i*(#ea%CC+ull)
E
#ea%Cte-pF
curre+tCte-pF
J
Else
E
curre+t-MrptrCte-pF
te-p-MlptrCcurre+tF
curre+tCte-pF
J
J
voi%traverse()
E
struct +o%e t1C#ea%F
i*(t1CC+ull)
pri+t*(GR+G)F
else
*or(Ft1XC+ullFt1-Mrptr)
E
pri+t*(G5%R+GBt1-Mi+*o)F
J
J
voi% i+sret()
E
struct +o%e +e$F
struct +o%et2C#ea%F
i+t +oBpBoptio+F
i*(t2CC+ull)
E
pri+t*(G+o ele-e+ts is i+ li+4e%listG)F
pri+t*(Gpleasei+sert i+to a+! ele-+ets i+ t#e li+4e%listR+G)F
exit()F
J
else
E
pri+t*(Ge+ter t#e +o to i+sert R+G)F
sca+*(GH%GBI+o)F
pri+t*(G1.i+sert at begi+i+g R+G)F
pri+t*(G2.i+sert at e+% R+G)F
pri+t*(G3.i+sert at -i%%le R+G)F
pri+t*(Ge+ter u r optio+ R+G)F
sca+*(GH%GBIoptio+)F
+e$C(struct +o%e)-alloc(si7eo*(struct(+o%e))F
+e$-MlptrC+ullF
+e$-Mi+*oC+oF
+e$-MrptrC+ullF
s$itc#(optio+)
E
case1A
+e$-MlptrCt2F
+e$-MlptrC+e$F
#ea%C+e$F
brea4F
case2A
*or(Ft-MrptrXC+ullFt2Ct2-Mrptr)
+e$-MlptrCt2F
t2-MrptrC+e$F
brea4F
case3A
pri+t*(Ge+ter t#e ele-e+ts a*ter $#ic# u $a+t to i+sert R+G)F
sca+*(GH%GBIp)F
*or(Ft2XC+ull II t2-Mi+*oXCpFt2Ct2-Mrptr)
i*(t2C+ull)
E
pri+t*(Gele-e+ts +ot *ou+% R+G)F
J
else
E
+e$-MrptrCt2-MrptrF
t2-Mrptr-MlptrC+e$F
t2-MprtrC+e$F
+e$-MlptrCt2F
J
brea4F
J
J
J
voi% %elete()
E
i+t *lagC&BeleF
struct +o%e t3C#ea%F
i*(t3CC+ull)
E
pri+t*(GR+ +oele-+etG)F
exit()F
J
else
E
pri+t*(Ge+ter t#e ele-t to be %elete%G)F
sca+*(GH%GBIele)F
$#ile(t3XC+ull)
E
i*(t3-Mi+*oCCele)
E
*lagC1F
i*(t3CC#ea%)
E
#ea%Ct3-MrptrF
#ea%-MrptrC+ullF
*ree(t3)F
J
else
E
i*(t3-MrptrXC+ull)
E
t3-MlptrCt3-MrptrF
t3-MrptrCt3-MlptrF
*ree(t3)F
J
else
E
t3-Mlptr-MrptrC+ullF
*ree(t3)F
J
J
J
t3Ct3-MptrF
J
i*(*lagCC&)
E
pri+t*(Gele-e+t +ot *ou+%R+G)F
J
J
J
#) 3e"ult:
1) ;+sert 2) <elete 3) <ispla!
E+ter c#oice *or circular "ueue 1
E+ter a+! ite- 1'
1) ;+sert 2) <elete 3) <ispla!
E+ter c#oice *or circular "ueue 1
E+ter a+! ite- 15
1) ;+sert 2) <elete 3) <ispla!
E+ter c#oice *or circular "ueue 1
E+ter a+! ite- 2&
1) ;+sert 2) <elete 3) <ispla!
E+ter c#oice *or circular "ueue 3
1' 15 2&
Experiment +! 8rogram to implement Eubble "ort
1) -./: 8rogram to implement Eubble "ort
2) -0123.T4/:
step1A ta4e *irst t$o ele-e+ts o* a list a+% co-pare t#e-
step2A i* t#e *irst ele-e+ts grater t#a+ seco+% t#e+ i+terc#a+ge else 4eep t#e values
as it
step3A repeat t#e step 2 u+til last co-pariso+ ta4es place
step'A reapeat step 1 to 3 u+til t#e list is sorte%
EF8E3./ENT +!: 8rogram to implement Eubble "ort
-./: 8rogram to implement Eubble "ort
#) 83213-/:
8rogram to implement Eubble "ort
Ki+clu%eLst%io.#M
-ai+()
E
i+t aV1&WBiB8Bte-pB+F
clear()F
pri+t*(GR+ e+ter t#e -ax +o.o* ele-e+ts u $a++a sort R+G)F
sca+*(GH%GBI+)F
pri+t*(GR+ e+ter t#e ele-e+ts u $a+t to sort R+G)F
*or(iC&FiL+Fi++)
E
sca+*(GH%GBIaViW)F
J
*or(iC&FiL+Fi++)
*or(8Ci+1F8L+F8++)
E
i*(aViWMaV8W)
E
te-pCaViWF
aViWCaV8WF
aV8WCte-pF
J
J
*or(iC&FiL+Fi++)
E
pri+t*(GH%RtGBaViW)F
J getc#()FJ
+) 3e"ult:
e+ter t#e -ax +o.o* ele-e+ts u $a++a sort
5
e+ter t#e ele-e+ts u $a+t to sort
1& 2& 15 ) '&
) 1& 15 2& '&
Experiment +<: 8rogram to implement Selection "ort
1) -./: 8rogram to implement Selection "ort
2) -0123.T4/:
step1A ta4e *irst a list o* u+sorte% values
step2A co+si%er t#e *irst ele-e+t as -i+i-u- ele-e+t store itsi+%exvalue i+ a
variable
step3Arepeat t#e step 2 u+till last co-pariso+ ta4es place
step'A co-pare t#e -i+i-u- $it# rest o* all ele-e+ts to *i+% -i+i-u- value a+%
i+terc#a+ge t#e -i+i-u- value $it# t#e *irst ele-e+t
step5A reapeat step 3 to ' u+til t#e list is sorte%/
#) 83213-/:
8rogram to implement Selection "ort
Ki+clu%eLst%io.#M
-ai+()
E
i+t aV1&WBiB8Bte-pB+F
i+t -i+BlocF
clear()F
pri+t*(GR+ e+ter t#e -ax +o.o* ele-e+ts u $a++a sort R+G)F
sca+*(GH%GBI+)F
pri+t*(GR+ e+ter t#e ele-e+ts u $a+t to sort R+G)F
*or(iC&FiL+Fi++)
E
sca+*(GH%GBIaViW)F
J
*or(iC&FiL+-1Fi++)
-i+CaViWF
locC1F
*or(8Ci+1F8LC+F8++)
E
i*(-i+MaV8W)
E
-i+CaV8WF
locC8F
J
J
J
te-pCaViWF
aViWCaVlocWF
aVlocWCte-pF
J
*or(iC&FiL+Fi++)
Epri+t*(GH%RtGBaViW)F
J
getc#()F
J
+) 3e"ult:
e+ter t#e -ax +o.o* ele-e+ts u $a++a sort
5
e+ter t#e ele-e+ts u $a+t to sort
1& 2& 15 ) '&
) 1& 15 2& '&
Experiment +>: 8rogram to implement .n"ertion "ort
1) -./: 8rogram to implement .n"ertion "ort
2) -0123.T4/:
step1A ta4e a list o* values
step2A co-pare t#e *irst t$o ele-e+ts o* a list i* *irst ele-e+t is greatert#a+ seco+%
i+terc#a+ge it else 4eep t#e list as it is.
step3A +o$ ta4e t#ree ele-e+ts *ro- t#e list a+%sort t#e- as *olloes
1tep'AAreapeat step 2 to 3 u+til t#elist is sorte%/
#) 83213-/: 8rogram to implement .n"ertion "ort
Ki+clu%eLst%io.#M
-ai+()
E
i+t aV1&WBiBpBte-pB+F
clear()F
pri+t*(GR+ e+ter t#e -ax +o.o* ele-e+ts u $a++a sort R+G)F
sca+*(GH%GBI+)F
pri+t*(GR+ e+ter t#e ele-e+ts u $a+t to sort R+G)F
*or(iC1FiLC+Fi++)
E
sca+*(GH%GBIaViW)F
J
aV&WC1&&F
*or(iC2FiLC+Fi++)
te-pCaViWF
pCi-1F
$#ile(te-pLaVpW)
E
aVp+1WCaVpWF
pCp-1F
J
aVp+1WCte-pF
J
*or(iC1FiLC+Fi++)
E
pri+t*(GH%RtGBaViW)F
J getc#()FJ
+) 3e"ult:
E+ter t#e -ax +o.o* ele-e+ts u $a+t to sort
5
E+ter t#e ele-e+ts u $a+t to sort
1& 2& 15 ) '&
) 1& 15 2& '&
Experiment +,: 8rogram to implement =uicC "ort
1) -./: 8rogram to implement =uicC "ort
2) -0123.T4/:
step1A ta4e *irst a list o* u+sorte% values
step2A ta4e *irstele-e+t as NpivotN
step3A 4eep t#e *irstele-e+t as NpivotN a+% correct its positio+ i+ t#e list
step'A %ivi%e t#e list i+to t$o base% o+ *irst ele-e+t
step5A co-bi+e t#e list
#) 83213-/:
8rogram to implement =uicC "ort
Ki+clu%eLst%io.#M
-ai+()
E
i+t aV1&WBiBle*tBrig#tB+F
i+t -i+BlocF
clear()F
pri+t*(GR+ e+ter t#e -ax +o.o* ele-e+ts u $a++a sort R+G)F
sca+*(GH%GBI+)F
pri+t*(GR+ e+ter t#e ele-e+ts u $a+t to sort R+G)F
*or(iC&FiL+Fi++)
E
sca+*(GH%GBIaViW)F
J
le*tC&F
rig#tC+-1F
"uic4sort(aBle*tBrig#t)F
%ispla!(aB+)F
J
"uic4sort(i+t aVWBi+t le*tBi+trig#t)
E
i+t te-pB*lagC1BiB8BpF
iCle*tF
8Crig#tF
pCaVle*tWF
i*(rig#tMle*t)
E
$#ile(*lag)
E
%o
E
i++F
J
$#ile(aViWLp II iLCrig#t)F
$#ile((aViWMp) II 8Mle*t)
8--F
i*(8Li)
*lagC&F
else
E
te-pCaViWF
aViWCaV8WF
aV8WCte-pF
J
J
te-pCaVlestWF
aVle*tWCaV8WF
aV8WCte-pF
"uic4sortVaBle*tB8-1WF
"uic4sortVaBiBrig#tWF
J
J
%ispla!(i+t aVWBi+t +)
E
i+t iF
*or(iC&FiL+Fi++)
E
pri+t*(GH%RtGBaViW)F
J
getc#()F
J
+) 3e"ult:
e+ter t#e -ax +o.o* ele-e+ts u $a++a sort
5
e+ter t#e ele-e+ts u $a+t to sort
1& 2& 15 ) '&
) 1& 15 2& '&
Experiment +A: 8rogram to implement 4eap "ort
1) -./: 8rogram to implement 4eap "ort
2) -0123.T4/:
step1A arra+ge ele-e+ts o* a list i+ correct *or- o* a bi+ar! tree
step2A re-ove top -ost ele-e+ts o* t#e #eap
step3A re arra+ge t#e re-ai+i+g ele-e+ts *ro- a #eap t#is process is co+ti+ue% till
$e get sorte% list
Experiment +A: 8rogram to implement 4eap "ort
1) -./: 8rogram to implement 4eap "ort
2) 83213-/:
8rogram to implement 4eap "ort
Ki+clu%eLst%io.#M
-ai+()
E
i+t aV1&WBiB8B+F
i+t -i+BlocF
clear()F
pri+t*(GR+ e+ter t#e -ax +o.o* ele-e+ts u $a++a sort R+G)F
sca+*(GH%GBI+)F
pri+t*(GR+ e+ter t#e ele-e+ts u $a+t to sort R+G)F
*or(iC&FiL+Fi++)
E
sca+*(GH%GBIaViW)F
J
#eapsort(aB+)F
%ispla!(aB+)F
J
#eapsort(i+taVWBi+t +)
E
i+t te-pBiB4e!B"F
create #eap(aB+)F
*or("C+F"M2F"--)
E
te-pCaViWF
aViWCaV"WF
aV"WCte-pF
iC1F
4e!CaV1WF
8C2F
i*((8+1)L")
i*(aV8+1WMaV8W)
8++F
$#ile(8LC("-1) II aV8WL4e!))
E
aViWCaV8WF
iC8F
8C2iF
i*((8+1)L")
i*(aV8+1WMaV8W)
8++F
else
i*(8M+)
8C+F
aViWC4e!F
J
JJ
#) 3e"ult:
e+ter t#e -ax +o.o* ele-e+ts u $a++a sort
5
e+ter t#e ele-e+ts u $a+t to sort
1& 2& 15 ) '&
) 1& 15 2& '&
Experiment !*: 8rogram to implement Einar& "earch
1) -./: 8rogram to implement Einar& "earch
2) 83213-/:
8rogram to implement Einar& "earch
Ki+clu%eLst%io.#M
-ai+()
E
i+t listV1&WB4e!B*ou+%B+u-BiF
i+t lo$B#ig#B-i%F
clrscr()F
pri+t*(GR+ e+ter t#e -ax +o.o* ele-e+ts u $a++a sort R+G)F
sca+*(GH%GBI+u-)F
pri+t*(GR+ e+ter t#e ele-e+ts u $a+t to sort R+G)F
*or(iC&FiL+u-Fi++)
E
sca+*(GH%GBIlistViW)F
J
pri+t*(Ge+ter t#e value to be searc#e%G)F
sca+*(GH%GBI4e!)F
lo$CoF
#ig#C+u--1F
$#ile(lo$LC#ig#)
E
-i%C(lo$+#ig#)/2F
i*(4e!CClistV-i%W)
E
pri+t*(Gsearc# is success*ulG)F
pri+t*(GR+ t#e ele-+ts is H%R+GBlistV-i%W)F
*ou+%C1F
brea4FJ
i*(4e!Llist(-i%))
#ig#C-i%-1F
else
i*(4e!Mlist(-i%))
lo$C-i%+1F
J
i*(*ou+%XC1)
pri+t*(Gseac# is u+success*ulG)F
getc#()F
J
#) 3e"ult:
e+ter t#e -ax +o.o* ele-e+ts u $a++a sort
5
e+ter t#e ele-e+ts u $a+t to sort
1 2 3 ' 5
e+ter t#e value to be searc#e%
3
searc# is success*ul
t#e ele-+ts is 3
Experiment !1: 8rogram to implement linear "earch
1) -./: 8rogram to implement linear "earch
2) 83213-/:
8rogram to implement linear "earch
Ki+clu%eLst%io.#M
-ai+()
E
i+t listV1&WB4e!B*ou+%B+u-BiF
clrscr()F
pri+t*(TE+ter +o. o* ele-e+ts A T)F
sca+*(TH%UBI+u-)F
pri+t*(TE+ter H% ele-e+tsR+UB+u-)F
*or(iC&FiL+u-Fi++)
sca+*(TH%UBlistViV)F
pri+t*(GR+ e+ter t#e value to be seac#e% R+G)F
sca+*(GH%GBI4e!)F
*or(iC&FiL+u-Fi++)
E
i*(4e!CClistViW)
E
pri+t*(GR+ H% ele-e+t is *ou+% at locatio+H%GBlistViWBi+1)F
*ou+%C1F
J
J
i*(*ou+%XC1)
E
pri+t*(searc# is u+sucess*ulG)F
J
getc#()F
J
#) 3e"ult:
E+ter +u-ber o* ele-e+ts A 5
E+ter 5 ele-e+ts
15 35 )2 '5 11
e+ter t#e value to be seac#e%
)2
)2 ele-e+t is *ou+% at locatio+ 3

You might also like