Sie sind auf Seite 1von 58

C PROGRAMMING LAB CYCLE WEEK WISE

WEEK 1
/*1.a) A Fibonacci Seqence i! "e#ine" a! #o$$o%!& '(e #i)!' an" !econ"
'e)*! in '(e !eqence a)e + an" 1. Sb!eqen'
'e)*! a)e #on" b, a""in- '(e .)ece"in- '%o 'e)*! in '(e !eqence. W)i'e a
C .)o-)a* 'o -ene)a'e
'(e #i)!' n 'e)*! o# '(e !eqence.
*/
#include <stdio.h>
void main()
{
int num1=0, num2=1,no,counter,fab;
clrscr();
rintf(!<==========="#$%#&' ($ )*+, (-. )*/$+&00* 1.#*.1 2" ($ + +$.
*+ 1.#*.1=========>!);
rintf(!3n3n3n3t3t.+(.# 4.+%(- $) 1.#*.1 (+) 5 !);
scanf(!6d!,7no);
rintf(!3n3n3t3t3t<8888)*/$+&00* 1.#*.18888>!);
rintf(!3n3n3t3t6d 6d!,num1,num2);
994$$" :*44 #2+ )$# 2 (*'. 4.11 *+ 1.#*.1 &1 (-.1. :&1 "#*+(., *+
&,;&+0.
for(counter = 1; counter <= no82; counter<<)
{
fab=num1 < num2;
rintf(! 6d!,fab);
num1=num2;
num2=fab;
=
>etch();
=
O'.'&
<==========="#$%#&' ($ )*+, (-. )*/$+&00* 1.#*.1 2" ($ + +$. *+
1.#*.1=========>
.+(.# 4.+%(- $) 1.#*.1 (+) 5 ?
<8888)*/$+&00* 1.#*.18888>
0 1 1 2 @
/*1.b) W)i'e a C .)o-)a* 'o -ene)a'e a$$ '(e .)i*e n*be)! be'%een 1 an"
n/ %(e)e n i! a 0a$e !..$ie" b, '(e !e). */
#include <stdio.h>
void main()
{
int no,counter,counter1,checA;
clrscr();
rintf(!<88888888888888888888888"#*'. +$. 1.#*.1888888888888888888888888>!);
rintf(!3n3n3n3t3t3t*+"2( (-. ;&42. $) +5 !);
scanf(!6d!,7no);
rintf(!3n3n(-. "#*'. +$. 1.#*.1 /9: 1 ($ 6d 5 3n3n!,no);
for(counter = 1; counter <= no; counter<<)
CP LAB MANUAL 1
{
checA = 0;
99(-*1 4$$" :*44 0-.0B & +$ ($ /. "#*'. +$. $# +$(.
for(counter1 = counter81; counter1 > 1 ; counter188)
if(counter6counter1 == 0)
{
checA<<; 99 *+0#.'.+( 0-.0B *) +$. *1 +$( & "#*'. +$.
breaA;
=
if(checA == 0)
rintf(!6d3t!,counter);
=
>etch();
=
O'.'&
<88888888888888888888888"#*'. +$. 1.#*.1888888888888888888888888>
*+"2( (-. ;&42. $) +5 1@
(-. "#*'. +$. 1.#*.1 /9: 1 ($ 1@ 5
1 2 @ ? C 11 1@
/* 1.c)W)i'e a C .)o-)a* 'o #in" '(e !* o# in"i0i"a$ "i-i'! o# a .o!i'i0e
in'e-e).*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num, A=1, sum=0;
clrscr();
rintf(!.nter the number Dhose di>its are to be added5!);

scanf(!6d!,7num);
Dhile(numE=0)
{
A=num610;
sum=sum<A;
A=num910;
num=A;
=
rintf(!1um of the di>its56d!,sum);
>etch();
=
O'.'&
.nter the number Dhose di>its are to be added5?FG
1um of the di>its522
WEEK 1
CP LAB MANUAL 2
/* 1.a)W)i'e a C .)o-)a* 'o ca$c$a'e '(e #o$$o%in- S*&
S*21341/15 647/75348/85649/95341+/1+5
*/
#include <stdio.h>
#include <math.h>
void main()
{
int counter,fHcoun;
float sum=0,I,oDer,fact;
clrscr();
rintf(!<88888888888888888888888"#$%#&' )$# 12' $) .J. 1.#*.188888888888888888>!);
rintf(!3n3n3t.J2&(*$+ 1.#*.1 5 18 KL292E < KLM9ME 8 KLN9NE < KLF9FE 8
KL10910E!);
rintf(!3n3n3n3t.+(.# ;&42. $) K 5 !);
scanf(!6f!,7I);
for(counter=0, oDer=0; oDer<=10; counter<<,oDer=oDer<2)
{
fact=1;
990&40 )&0($#*&4 $) "$:.# ;&42.
for(fHcoun=oDer; fHcoun>=1; fHcoun88)
fact O= fHcoun;
99.J. )$# 12' 1.#*.1
sum=sum<(oD(81,counter)O(oD(I,oDer)9fact));
=
rintf(!12' 5 6f!,sum);
>etch();
=
O'.'&
<88888888888888888888888"#$%#&' )$# 12' $) .J. 1.#*.188888888888888888888888>
.J2&(*$+ 1.#*.1 5 18 KL292E < KLM9ME 8 KLN9NE < KLF9FE 8 KL10910E
.+(.# ;&42. $) K 5 2
12' 5 80.M1N1??
/* 1.b)W)i'e a C .)o-)a* 'oe #in" '(e )oo'! o# a qa")a'ic eqa'ion. */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,root1,root2;
clrscr();
rintf(!3n .nter values of a,b,c for findin> roots of a Puadratic eP53n!);
scanf(!6f6f6f!,7a,7b,7c);
9OchecAin> conditionO9
if(bOb>MOaOc)
{
root1=8b<sPrt(bOb8MOaOc)92Oa;
root2=8b8sPrt(bOb8MOaOc)92Oa;
rintf(!3nOOOOO#$$(1 &#.OOOOO3n!);
rintf(!3n root1=6f3n root2=6f!,root1,root2);
=
else
rintf(!3n *ma>inarQ #oots.!);
>etch();
=
O'.'5
.nter values of a,b,c for findin> roots of a Puadratic eP5
1
2
@
*ma>inarQ #oots.
WEEK :
CP LAB MANUAL 3
/*:.a) W)i'e C .)o-)a*! '(a' !e bo'( )ec)!i0e an" non3)ec)!i0e
#nc'ion!
;o #in" '(e #ac'o)ia$ o# a -i0en in'e-e).*/
#include<stdio.h>
#include<conio.h>
unsi>ned int recrHfactorial(int n);
unsi>ned int iterHfactorial(int n);
void main()
{
int n,i;
lon> fact;
clrscr();
rintf(!.nter the number5 !);
scanf(!6d!,7n);
if(n==0)
rintf(!)actorial of 0 is 13n!);
else
{
rintf(!)actorial of 6d 2sin> #ecursive )unction is 6d3n!,n,recrHfactorial(n));
rintf(!)actorial of 6d 2sin> +on8#ecursive )unction is 6d3n!,n,iterHfactorial(n));
=
>etch();
=
9O #ecursive )unctionO9
unsi>ned int recrHfactorial(int n) {
return n>=1 R n O recrHfactorial(n81) 5 1;
=
9O +on8#ecursive )unctionO9
unsi>ned int iterHfactorial(int n) {
int accu = 1;
int i;
for(i = 1; i <= n; i<<) {
accu O= i;
=
return accu;
=
O'.'5
.nter the number5 N
)actorial of N 2sin> #ecursive )unction is C20
)actorial of N 2sin> +on8#ecursive )unction is C20
/* :.b)W)i'e C .)o-)a*! '(a' !e bo'( )ec)!i0e an" non3)ec)!i0e
#nc'ion!
;o #in" '(e GC< =-)ea'e!' co**on "i0i!o)) o# '%o -i0en in'e-e)!.*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
unsi>ned int %cd#ecursive(unsi>ned m, unsi>ned n);
unsi>ned int %cd+on#ecursive(unsi>ned ,unsi>ned P);
int main(void)
{
int a,b,i%cd;
clrscr();
rintf(!.nter the tDo numbers Dhose %0, is to be found5 !);
scanf(!6d6d!,7a,7b);
rintf(!%0, of 6d and 6d 2sin> #ecursive )unction is
6d3n!,a,b,%cd#ecursive(a,b));
rintf(!%0, of 6d and 6d 2sin> +on8#ecursive )unction is
6d3n!,a,b,%cd+on#ecursive(a,b));
>etch();
=
9O #ecursive )unctionO9
unsi>ned int %cd#ecursive(unsi>ned m, unsi>ned n)
{
if(n>m)
return %cd#ecursive(n,m);
if(n==0)
return m;
else
return %cd#ecursive(n,m6n); =
9O +on8#ecursive )unctionO9
unsi>ned int %cd+on#ecursive(unsi>ned ,unsi>ned P)
CP LAB MANUAL 4
{
unsi>ned remainder;
remainder = 8(9POP);
if(remainder==0)
return P;
else
%cd#ecursive(P,remainder);
=
O'.'5
.nter the tDo numbers Dhose %0, is to be found5 12?
N2?
%0, of 12? and N2? 2sin> #ecursive )unction is 12?
%0, of 12? and N2? 2sin> +on8#ecursive )unction is 12?
/* :.c)W)i'e C .)o-)a*! '(a' !e bo'( )ec)!i0e an" non3)ec)!i0e
#nc'ion! ;o !o$0e ;o%e)! o# >anoi .)ob$e*.*/
#include<conio.h>
#include<stdio.h>
9O +on8#ecursive )unctionO9
void hanoi+on#ecursion(int num,char sndl,char indl,char dndl)
{
char stAnS100T,stAsndlS100T,stAindlS100T,stAdndlS100T,stAaddS100T,tem;
int to,add;
to=+244;
one5
if(num==1)
{
rintf(!3n'ove to disA from needle 6c to needle 6c !,sndl,dndl);
>oto four;
=
tDo5
to=to<1;
stAnStoT=num;
stAsndlStoT=sndl;
stAindlStoT=indl;
stAdndlStoT=dndl;
stAaddStoT=@;
num=num81;
sndl=sndl;
tem=indl;
indl=dndl;
dndl=tem;
>oto one;
three5
rintf(!3n'ove to disA from needle 6c to needle 6c !,sndl,dndl);
to=to<1;
stAnStoT=num;
stAsndlStoT=sndl;
stAindlStoT=indl;
stAdndlStoT=dndl;
stAaddStoT=?;
num=num81;
tem=sndl;
sndl=indl;
indl=tem;
dndl=dndl;
>oto one;
four5
if(to==+244)
return;
num=stAnStoT;
sndl=stAsndlStoT;
indl=stAindlStoT;
dndl=stAdndlStoT;
CP LAB MANUAL 5
add=stAaddStoT;
to=to81;
if(add==@)
>oto three;
else if(add==?)
>oto four;
=
/* Rec)!i0e Fnc'ion*/
void hanoi#ecursion( int num,char ndl1, char ndl2, char ndl@)
{
if ( num == 1 ) {
rintf( !'ove to disA from needle 6c to needle 6c.!, ndl1, ndl2 );
return;
=
hanoi#ecursion( num 8 1,ndl1, ndl@, ndl2 );
rintf( !'ove to disA from needle 6c to needle 6c.!, ndl1, ndl2 );
hanoi#ecursion( num 8 1,ndl@, ndl2, ndl1 );
=
void main()
{
int no;
clrscr();
rintf(!.nter the no. of disAs to be transferred5 !);
scanf(!6d!,7no);
if(no<1)
rintf(!3n(hereUs nothin> to move.!);
else
rintf(!+on8#ecursive!);
hanoi+on#ecursion(no,U&U,U/U,U0U);
rintf(!3n#ecursive!);
hanoi#ecursion(no,U&U,U/U,U0U);
>etch();
=
O'.'5
.nter the no. of disAs to be transferred5 @
+on8#ecursive
'ove to disA from needle & to needle 0
'ove to disA from needle & to needle /
'ove to disA from needle 0 to needle /
'ove to disA from needle & to needle 0
'ove to disA from needle / to needle &
'ove to disA from needle / to needle 0
'ove to disA from needle & to needle 0
#ecursive'ove to disA from needle & to needle /.'ove to disA from needle & to
needle 0.'ove to disA from needle / to needle 0.'ove to disA from needle & to
needle /.'ove to disA from needle 0 to needle &.'ove to disA from needle 0 to
needle /.'ove to disA from needle & to needle /.
CP LAB MANUAL 6
WEEK 7
/*7.a) W)i'e a C .)o-)a*/ %(ic( 'a?e! '%o in'e-e) o.e)an"! an" one
o.e)a'o) #o)* '(e !e)/
.e)#o)*! '(e o.e)a'ion an" '(en .)in'! '(e )e!$'.
=Con!i"e) '(e o.e)a'o)! 6/3/*/ // @ an" !e S%i'c( S'a'e*en')
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,res,ch;
clrscr();
rintf(!3t OOOOOOOOOOOOOOOOOOOOO!);
rintf(!3n3t'.+23n!);
rintf(!3tOOOOOOOOOOOOOOOOOOOO!);
rintf(!3n3t(1)&,,*(*$+!);
rintf(!3n3t(2)12/(#&0(*$+!);
rintf(!3n3t(@)'24(*"4*0&(*$+!);
rintf(!3n3t(M),*;*1*$+!);
rintf(!3n3t(?)#.'&*+,.#!);
rintf(!3n3t(0).K*(!);
rintf(!3n3tOOOOOOOOOOOOOOOOOOOO!);
rintf(!3n3n3t.nter Qour choice5!);
scanf(!6d!,7ch);
if(ch<=? 7 ch>0)
{
rintf(!.nter tDo numbers53n!);
scanf(!6d6d!,7a,7b);
=
sDitch(ch)
{
case 15
res=a<b;
rintf(!3n &ddition56d!,res);
breaA;
case 25
res=a8b;
rintf(!3n 1ubtraction56d!,res);
breaA;
case @5
res=aOb;
rintf(!3n 'ultilication56d!,res);
breaA;
case M5
res=a9b;
rintf(!3n ,ivision56d!,res);
breaA;
case ?5
res=a6b;
rintf(!3n #emainder56d!,res);
breaA;
case 05
rintf(!3n 0hoice (erminated!);
eIit();
breaA;
default5
rintf(!3n *nvalid 0hoice!);
=
>etch();
=
O'.'&
CP LAB MANUAL 7
OOOOOOOOOOOOOOOOOOOOO
'.+2
OOOOOOOOOOOOOOOOOOOO
(1)&,,*(*$+
(2)12/(#&0(*$+
(@)'24(*"4*0&(*$+
(M),*;*1*$+
(?)#.'&*+,.#
(0).K*(
OOOOOOOOOOOOOOOOOOOO
.nter Qour choice5?
.nter tDo numbers5
N2?
12?
#emainder50
/* 7.b) ;(e 'o'a$ "i!'ance ')a0e$$e" b, 0e(ic$e in A'A !econ"! i! -i0en b,
"i!'ance 2 '61/1a'1 %(e)e AA an" AaA a)e '(e ini'ia$ 0e$oci', =*/!ec.)
an" acce$e)a'ion =*/!ec1). W)i'e C .)o-)a* 'o #in" '(e "i!'ance
')a0e$$e" a' )e-$a) in'e)0a$! o# 'i*e -i0en '(e 0a$e! o# AA an" AaA. ;(e
.)o-)a* !(o$" .)o0i"e '(e #$e4ibi$i', 'o '(e !e) 'o !e$ec' (i! o%n 'i*e
in'e)0a$! an" )e.ea' '(e ca$c$a'ion! #o) "i##e)en' 0a$e! o# AA an" AaA.
*/
#include <stdio.h>
#include <math.h>
void main()
{
int timHintrval, counter,time;
float accl, distance=0, velos;
clrscr();
rintf(!<==========="#$%#&' )$# 0&40 ($(&4 ,*1(&+0. (#&;.4., /V &
;.0-*&4===========>!);
rintf(!3n3n3n3t3t3t+$ $) (*'. *+(.#;&41 5 !);
scanf(!6d!,7timHintrval);
for(counter = 1; counter <= timHintrval; counter<<)
{
rintf(!3n3t3t3t&( (6d (*'.(sec) 5 !,counter);
scanf(!6d!,7time);
rintf(!3t3t3t;.4$0*(V &( 6d sec (m9sec) 5 !,time);
scanf(!6f!,7velos);
rintf(!3t3t3t&004.#&(*$+ &( 6d sec (m9secL2)5 !,time);
scanf(!6f!,7accl);
distance <= (velosOtime < (acclOoD(time,2))92);
=
rintf(!3n3n3n3t($(&4 ,*1(&+0. (#&;.44., /V ;.-*04. *+ 6d *+(.#;&41 $) (*'.
5 6f!,timHintrval,distance);
>etch();
=
O'.'5
<======="#$%#&' )$# 0&40 ($(&4 ,*1(&+0. (#&;.4., /V &
;.0-*0&4===========>
+$ $) (*'. *+(.#;&41 5 ?
&( (1 (*'.(sec) 5 20
;.4$0*(V &( 20 sec (m9sec) 5 ?0
&004.#&(*$+ &( 20 sec (m9secL2)5 N0
&( (2 (*'.(sec) 5 @0
;.4$0*(V &( @0 sec (m9sec) 5 N0
&004.#&(*$+ &( @0 sec (m9secL2)5 C0
&( (@ (*'.(sec) 5 M0
;.4$0*(V &( M0 sec (m9sec) 5 F0
&004.#&(*$+ &( M0 sec (m9secL2)5 G0
&( (M (*'.(sec) 5 ?0
;.4$0*(V &( ?0 sec (m9sec) 5 G0
&004.#&(*$+ &( ?0 sec (m9secL2)5 100
&( (? (*'.(sec) 5 N0
;.4$0*(V &( N0 sec (m9sec) 5 100
&004.#&(*$+ &( N0 sec (m9secL2)5 120
CP LAB MANUAL 8
/*7.c) W)i'e a C .)o-)a* '(a' !e! #nc'ion! 'o .e)#o)* '(e #o$$o%in-&
i) A""i'ion o# ;%o Ma')ice!
ii) M$'i.$ica'ion o# ;%o Ma')ice!
*/
#include<stdio.h>
void main()
{
int ch,i,W,m,n,,P,A,r1,c1,aS10TS10T,bS10TS10T,cS10TS10T;
clrscr();
rintf(!OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!);
rintf(!3n3t3t'.+2!);
rintf(!3nOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!);
rintf(!3nS1T&,,*(*$+ $) (:$ '&(#*0.1!);
rintf(!3nS2T'24(*"4*0&(*$+ $) (:$ '&(#*0.1!);
rintf(!3nS0T.K*(!);
rintf(!3nOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!);
rintf(!3n3t.nter Qour choice53n!);
scanf(!6d!,7ch);
if(ch<=2 7 ch>0)
{
rintf(!;alid 0hoice3n!);
=
sDitch(ch)
{
case 15
rintf(!*nut roDs and columns of & 7 / 'atriI5!);
scanf(!6d6d!,7r1,7c1);
rintf(!.nter elements of matriI &53n!);
for(i=0;i<r1;i<<)
{
for(W=0;W<c1;W<<)
scanf(!6d!,7aSiTSWT);
=
rintf(!.nter elements of matriI /53n!);
for(i=0;i<r1;i<<)
{
for(W=0;W<c1;W<<)
scanf(!6d!,7bSiTSWT);
=
rintf(!3n ====='atriI &ddition=====3n!);
for(i=0;i<r1;i<<)
{
for(W=0;W<c1;W<<)
rintf(!6?d!,aSiTSWT<bSiTSWT);
rintf(!3n!);
=
breaA;
case 25
rintf(!*nut roDs and columns of & matriI5!);
scanf(!6d6d!,7m,7n);
rintf(!*nut roDs and columns of / matriI5!);
scanf(!6d6d!,7,7P);
if(n==)
{
rintf(!matrices can be multilied3n!);
rintf(!resultant matriI is 6dO6d3n!,m,P);
rintf(!*nut & matriI3n!);
readHmatriI(a,m,n);
rintf(!*nut / matriI3n!);
/*Fnc'ion ca$$ 'o )ea" '(e *a')i4*/
readHmatriI(b,,P);
9O)unction for 'ultilication of tDo matricesO9
rintf(!3n ====='atriI 'ultilication=====3n!);
for(i=0;i<m;<<i)

for(W=0;W<P;<<W)
CP LAB MANUAL 9
{
cSiTSWT=0;
for(A=0;A<n;<<A)
cSiTSWT=cSiTSWT<aSiTSATObSATSWT;
=
rintf(!#esultant of tDo matrices53n!);
DriteHmatriI(c,m,P);
=
/*en" i#*/
else
{
rintf(!'atrices cannot be multilied.!);
=
9Oend elseO9
breaA;
case 05
rintf(!3n 0hoice (erminated!);
eIit();
breaA;
default5
rintf(!3n *nvalid 0hoice!);
=
>etch();
=
/*Fnc'ion )ea" *a')i4*/
int readHmatriI(int aS10TS10T,int m,int n)
{
int i,W;
for(i=0;i<m;i<<)
for(W=0;W<n;W<<)
scanf(!6d!,7aSiTSWT);
return 0;
=
/*Fnc'ion 'o %)i'e '(e *a')i4*/
int DriteHmatriI(int aS10TS10T,int m,int n)
{
int i,W;
for(i=0;i<m;i<<)
{
for(W=0;W<n;W<<)
rintf(!6?d!,aSiTSWT);
rintf(!3n!);
=
return 0;
=
O'.'&
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
'.+2
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
S1T&,,*(*$+ $) (:$ '&(#*0.1
S2T'24(*"4*0&(*$+ $) (:$ '&(#*0.1
S0T.K*(
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
.nter Qour choice5
2
;alid 0hoice
*nut roDs and columns of & matriI52
@
*nut roDs and columns of / matriI5@
2
matrices can be multilied
resultant matriI is 2O2
*nut & matriI
2
?
N
@
?
M
*nut / matriI
F
CP LAB MANUAL 10
WEEK B
/*B.a) W)i'e a C .)o-)a* 'o #in" bo'( '(e $a)-e!' an" !*a$$e!' n*be) in a
$i!' o# in'e-e)!*/
main( )
{
float lar>est(float aS T, int n);
float valueSMT = {2.?,8M.C?,1.2,@.NC=;
rintf(!6f3n!, lar>est(value,M));
=
float lar>est(float aST, int n)
{
int i;
float maI;
maI = aS0T;
for(i = 1; i < n; i<<)
if(maI < aSiT)
maI = aSiT;
return(maI);
=
O'.'&
@.NC0000
/* B.b)W)i'e a C .)o-)a* '(a' !e! #nc'ion! 'o .e)#o)* '(e #o$$o%in-&
i) A""i'ion o# ;%o Ma')ice!
ii) M$'i.$ica'ion o# ;%o Ma')ice!*/
#include<stdio.h>
void main()
{
int ch,i,W,m,n,,P,A,r1,c1,aS10TS10T,bS10TS10T,cS10TS10T;
clrscr();
rintf(!OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!);
rintf(!3n3t3t'.+2!);
rintf(!3nOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!);
rintf(!3nS1T&,,*(*$+ $) (:$ '&(#*0.1!);
rintf(!3nS2T'24(*"4*0&(*$+ $) (:$ '&(#*0.1!);
rintf(!3nS0T.K*(!);
rintf(!3nOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!);
rintf(!3n3t.nter Qour choice53n!);
scanf(!6d!,7ch);
if(ch<=2 7 ch>0)
{
rintf(!;alid 0hoice3n!);
=
sDitch(ch)
{
case 15
rintf(!*nut roDs and columns of & 7 / 'atriI5!);
scanf(!6d6d!,7r1,7c1);
rintf(!.nter elements of matriI &53n!);
for(i=0;i<r1;i<<)
{
for(W=0;W<c1;W<<)
scanf(!6d!,7aSiTSWT);
=
rintf(!.nter elements of matriI /53n!);
for(i=0;i<r1;i<<)
{
for(W=0;W<c1;W<<)
scanf(!6d!,7bSiTSWT);
=
rintf(!3n ====='atriI &ddition=====3n!);
for(i=0;i<r1;i<<)
{
for(W=0;W<c1;W<<)
rintf(!6?d!,aSiTSWT<bSiTSWT);
rintf(!3n!);
=
breaA;
case 25
rintf(!*nut roDs and columns of & matriI5!);
scanf(!6d6d!,7m,7n);
rintf(!*nut roDs and columns of / matriI5!);
scanf(!6d6d!,7,7P);
if(n==)
CP LAB MANUAL 11
{
rintf(!matrices can be multilied3n!);
rintf(!resultant matriI is 6dO6d3n!,m,P);
rintf(!*nut & matriI3n!);
readHmatriI(a,m,n);
rintf(!*nut / matriI3n!);
9O)unction call to read the matriIO9
readHmatriI(b,,P);
9O)unction for 'ultilication of tDo matricesO9
rintf(!3n ====='atriI 'ultilication=====3n!);
for(i=0;i<m;<<i)
for(W=0;W<P;<<W)
{
cSiTSWT=0;
for(A=0;A<n;<<A)
cSiTSWT=cSiTSWT<aSiTSATObSATSWT;
=
rintf(!#esultant of tDo matrices53n!);
DriteHmatriI(c,m,P);
=
9Oend ifO9
else
{
rintf(!'atrices cannot be multilied.!);
=
9Oend elseO9
breaA;
case 05
rintf(!3n 0hoice (erminated!);
eIit();
breaA;
default5
rintf(!3n *nvalid 0hoice!);
=
>etch();
=
/*Fnc'ion )ea" *a')i4*/
int readHmatriI(int aS10TS10T,int m,int n)
{
int i,W;
for(i=0;i<m;i<<)
for(W=0;W<n;W<<)
scanf(!6d!,7aSiTSWT);
return 0;
=
9O)unction to Drite the matriIO9
int DriteHmatriI(int aS10TS10T,int m,int n)
{
int i,W;
for(i=0;i<m;i<<)
{
for(W=0;W<n;W<<)
rintf(!6?d!,aSiTSWT);
rintf(!3n!);
=
return 0;
=
O'.'&
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
'.+2
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
S1T&,,*(*$+ $) (:$ '&(#*0.1
S2T'24(*"4*0&(*$+ $) (:$ '&(#*0.1
S0T.K*(
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
.nter Qour choice5
2 ;alid 0hoice
*nut roDs and columns of & matriI5?
1 *nut roDs and columns of / matriI51
? matrices can be multilied
resultant matriI is ?O? *nut & matriI 1 @ N?*nut / matriI CF
WEEK8
CP LAB MANUAL 12
/* 8.a)W)i'e a C .)o-)a* '(a' !e! #nc'ion! 'o .e)#o)* '(e #o$$o%in-
o.e)a'ion!& ;o in!e)' a !b3!')in- in 'o -i0en *ain !')in- #)o* a -i0en
.o!i'ion.
*/
#include <stdio.h>
#include <conio.h>
#include <strin>.h>
void main()
{
char aS10T;
char bS10T;
char cS10T;
int =0,r=0,i=0;
int t=0;
int I,>,s,n,o;
clrscr();
uts(!.nter )irst 1trin>5!);
>ets(a);
uts(!.nter 1econd 1trin>5!);
>ets(b);
rintf(!.nter the osition Dhere the item has to be inserted5 !);
scanf(!6d!,7);
r = strlen(a);
n = strlen(b);
i=0;
99 0oQin> the inut strin> into another arraQ
Dhile(i <= r)
{
cSiT=aSiT;
i<<;
=
s = n<r;
o = <n;
99 &ddin> the sub8strin>
for(i=;i<s;i<<)
{
I = cSiT;
if(t<n)
{
aSiT = bStT;
t=t<1;
=
aSoT=I;
o=o<1;
=
rintf(!6s!, a);
>etch();
=
O'.'&
.nter )irst 1trin>5
chandana
.nter 1econd 1trin>5
raviAumar
.nter the osition Dhere the item has to be inserted5 F
chandanaraviAumar
/* 8.b)W)i'e a C .)o-)a* 'o "e'e)*ine i# '(e -i0en !')in- i! a .a$in")o*e o)
no' */
#include<stdio.h>
#include<strin>.h>
enum /oolean{false,true=;
enum /oolean *s"alindrome(char strin>ST)
{
int left,ri>ht,len=strlen(strin>);
enum /oolean matched=true;
if(len==0)
return 0;
left=0;
ri>ht=len81;
9O 0omare the first and last letter,second 7 second last 7 so on O9
Dhile(left<ri>ht77matched)
{
if(strin>SleftTE=strin>Sri>htT)
CP LAB MANUAL 13
matched=false;
else
{
left<<;
ri>ht88;
=
=
return matched;
=
int main()
{
char strin>SM0T;
clrscr();
rintf(!OOOO"ro>ram to test if the >iven strin> is a alindromeOOOO3n!);
rintf(!.nter a strin>5!);
scanf(!6s!,strin>);
if(*s"alindrome(strin>))
rintf(!(he >iven strin> 6s is a alindrome3n!,strin>);
else
rintf(!(he >iven strin> 6s is not a alindrome3n!,strin>);
>etch();
return 0;
=
O'.'&
OOOO"ro>ram to test if the >iven strin> is a alindromeOOOO
.nter a strin>5malaQalam
(he >iven strin> malaQalam is a alindrome
/* 8.c)W)i'e a C .)o-)a* '(a' !e! #nc'ion! 'o .e)#o)* '(e #o$$o%in-
o.e)a'ion!& ;o "e$e'e n C(a)ac'e)! #)o* a -i0en .o!i'ion in a -i0en !')in-.
*/
#include <stdio.h>
#include <conio.h>
#include <strin>.h>
void delchar(char OI,int a, int b);
void main()
{
char strin>S10T;
int n,os,;
clrscr();
uts(!.nter the strin>!);
>ets(strin>);
rintf(!.nter the osition from Dhere to delete!);
scanf(!6d!,7os);
rintf(!.nter the number of characters to be deleted!);
scanf(!6d!,7n);
delchar(strin>, n,os);
>etch();
=
99 )unction to delete n characters
void delchar(char OI,int a, int b)
{
if ((a1) <= strlen(I))
{
strcQ(7ISb81T,7ISa1T);
uts(I);
=
=
O'.'&
.nter the strin>
raviAumar
.nter the osition from Dhere to delete?
.nter the number of characters to be deleted?
ravi
WEEK C
CP LAB MANUAL 14
/* C.a)W)i'e a C .)o-)a* 'o con' '(e $ine!/ %o)"! an" c(a)ac'e)! in a -i0en
'e4'*/
99"ro>ram
#include <stdio.h>
main()
{
char lineSF1T, ctr;
int i,c,
end = 0,
characters = 0,
Dords = 0,
lines = 0;
rintf(!B.V *+ (-. (.K(.3n!);
rintf(!%*;. $+. 1"&0. &)(.# .&0- :$#,.3n!);
rintf(!:-.+ 0$'"4.(.,, "#.11 U#.(2#+U.3n3n!);
Dhile( end == 0)
{
9O #eadin> a line of teIt O9
c = 0;
Dhile((ctr=>etchar()) E= U3nU)
lineSc<<T = ctr;
lineScT = U30U;
9O countin> the Dords in a line O9
if(lineS0T == U30U)
breaA ;
else
{
Dords<<;
for(i=0; lineSiT E= U30U;i<<)
if(lineSiT == U U XX lineSiT == U3tU)
Dords<<;
=
9O countin> lines and characters O9
lines = lines <1;
characters = characters < strlen(line);
=
rintf (!3n!);
rintf(!+umber of lines = 6d3n!, lines);
rintf(!+umber of Dords = 6d3n!, Dords);
rintf(!+umber of characters = 6d3n!, characters);
=
O'.'5
B.V *+ (-. (.K(.
%*;. $+. 1"&0. &)(.# .&0- :$#,.
:-.+ 0$'"4.(.,, "#.11 U#.(2#+U.
&dmiration is a verQ short8lived assion.
&dmiration involves a >lorious obliPuitQ of vision.
&lDaQs De liAe those Dho admire us but De do not
liAe those Dhom De admire.
)ools admire, but men of sense arove.
+umber of lines = ?
+umber of Dords = @N
+umber of characters = 20?
/*C.b) W)i'e a C .)o-)a* '(a' "i!.$a,! '(e .o!i'ion o) in"e4 in '(e !')in- S
%(e)e '(e !')in- ; be-in!/ o) 3 1 i# S "oe!nA' con'ain ;.
*/
#include<stdio.h>
#include<strin>.h>
#include<conio.h>
void main()
{
char sS@0T, tS20T;
char Ofound;
clrscr();
9O .nterin> the main strin> O9
uts(!.nter the first strin>5 !);
>ets(s);
9O .nterin> the strin> Dhose osition or indeI to be dislaQed O9
uts(!.nter the strin> to be searched5 !);
>ets(t);
9O1earchin> strin> t in strin> s O9
CP LAB MANUAL 15
found=strstr(s,t);
if(found)
rintf(!1econd 1trin> is found in the )irst 1trin> at 6d osition.3n!,found8s);
else
rintf(!81!);
>etch();
=
O'.'&
.nter the first strin>5
*Um ursuin> first Qear of the four Qear /(ech course
.nter the strin> to be searched5
Qear
1econd 1trin> is found in the )irst 1trin> at 1G osition.
WEEK 9
/* 9.a)W)i'e a C .)o-)a* 'o -ene)a'e Pa!ca$A! ')ian-$e. */
#include<stdio.h>
#include<conio.h>
void main()
{
int bin,,P,r,I;
clrscr();
bin=1;
P=0;
rintf(!#oDs Qou Dant to inut5!);
scanf(!6d!,7r);
rintf(!3n"ascalUs (rian>le53n!);
Dhile(P<r)
{
for(=M08@OP;>0;88)
rintf(! !);
for(I=0;I<=P;<<I)
{
if((I==0)XX(P==0))
bin=1;
else
bin=(binO(P8I<1))9I;
rintf(!6Nd!,bin);
=
rintf(!3n!);
<<P;
=
>etch();
=
O'.'&
#oDs Qou Dant to inut5G
"ascalUs (rian>le5
1
1 1
1 2 1
1 @ @ 1
1 M N M 1
1 ? 10 10 ? 1
1 N 1? 20 1? N 1
1 C 21 @? @? 21 C 1
1 F 2F ?N C0 ?N 2F F 1
/* 9.b)W)i'e a C .)o-)a* 'o con!')c' a .,)a*i" o# n*be)!. */
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,Q,I=@?;
clrscr();
rintf(!3n.nter the number to >enerate the Qramid53n!);
scanf(!6d!,7num);
for(Q=0;Q<=num;Q<<)
{
9O(I8coordinate,Q8coordinate)O9
>otoIQ(I,Q<1);
CP LAB MANUAL 16
9Ofor dislaQin> di>its toDards the left and ri>ht of YeroO9
for(i=08Q;i<=Q;i<<)
rintf(!6@d!,abs(i));
I=I8@;
=
>etch();
=
O'.'5
0
.nter the number to 1 0 1
>enerate the Qramid5 N 2 1 0 1 2
@ 2 1 0 1 2 @
M @ 2 1 0 1 2 @ M
? M @ 2 1 0 1 2 @ M ?
N ? M @ 2 1 0 1 2 @ M ? N
WEEK D
/*D.a)W)i'e a C .)o-)a* 'o )ea" in '%o n*be)!/ 4 an" n/ an" '(en
co*.'e '(e !* o# '(i! -eo*e')ic .)o-)e!!ion&
16464164:6EEEE.64n Fo) e4a*.$e& i# n i! : an" 4 i! B/ '(en '(e .)o-)a*
co*.'e! 16B61B611B.
P)in' 4/ n/ '(e !* Pe)#o)* e))o) c(ec?in-. Fo) e4a*.$e/ '(e #o)*$a "oe!
no' *a?e !en!e
#o) ne-a'i0e e4.onen'! 3 i# n i! $e!! '(an +. >a0e ,o) .)o-)a* .)in' an
e))o) *e!!a-e i# nF+/
'(en -o bac? an" )ea" in '(e ne4' .ai) o# n*be)! o# %i'(o' co*.'in- '(e
!*.
A)e an, 0a$e! o# 4 a$!o i$$e-a$ G I# !o/ 'e!' #o) '(e* 'oo. */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int sHsum,i,I,n;
clrscr();
rintf(!.nter the values for I and n5!);
scanf(!6d 6d!,7I,7n);
if(n<=0 XX I<=0)
{
rintf(!;alue is not valid3n!);
=
else
{
rintf(!;alue is valid3n!);
sHsum=1;
for(i=1;i<=n;i<<)
{
sHsum=sHsum<oD(I,i);
=
rintf(!1um of series=6d3n!,sHsum);
=
>etch();
=
O'.'&
.nter the values for I and n5N
10
;alue is valid
1um of series=110?G
CP LAB MANUAL 17
WEEK 1+
/*1+.a)1H! co*.$e*en' o# a n*be) i! ob'aine" b, !cannin- i' #)o*
)i-(' 'o $e#' an" co*.$e*en'in- a$$ '(e bi'! a#'e) '(e #i)!' a..ea)ance
o# a 1. ;(! 1H! co*.$e*en' o# 111++ i! ++1++. W)i'e a C .)o-)a* 'o
#in" '(e 1H! co*.$e*en' o# a bina), n*be).*/
#include <stdio.h>
#include<conio.h>
void comlement (char Oa);
void main()
{
char aS1NT;
int i;
clrscr();
rintf(!.nter the binarQ number!);
>ets(a);
for(i=0;aSiTE=U30U; i<<)
{
if (aSiTE=U0U 77 aSiTE=U1U)
{
rintf(!(he number entered is not a binarQ number. .nter the correct number!);
eIit(0);
=
=
comlement(a);
>etch();
=
void comlement (char Oa)
{
int l, i, c=0;
char bS1NT;
l=strlen(a);
for (i=l81; i>=0; i88)
{
if (aSiT==U0U)
bSiT=U1U;
else
bSiT=U0U;
=
for(i=l81; i>=0; i88)
{
if(i==l81)
{
if (bSiT==U0U)
bSiT=U1U;
else
{
bSiT=U0U;
c=1;
=
=
else
{
if(c==1 77 bSiT==U0U)
{
bSiT=U1U;
c=0;
=
else if (c==1 77 bSiT==U1U)
{
bSiT=U0U;
c=1;
=
=
=
bSlT=U30U;
rintf(!(he 2Us comlement is 6s!, b);
=
O'.'&
.nter the binarQ number01110
(he 2Us comlement is 10010
CP LAB MANUAL 18
/* 1+.b) W)i'e a C .)o-)a* 'o con0e)' a Ro*an n*e)a$ 'o i'!
"eci*a$ eqi0a$en'. */
#include<stdio.h>
#include<conio.h>
#include<strin>.h>
#include<stdlib.h>
void main()
{
int Oa,len,i,W,A;
char Orom;
clrscr();
rintf(!.nter the #oman +umeral5!);
scanf(!6s!,rom);
len=strlen(rom);
for(i=0;i<len;i<<)
{
if(romSiT==U*U)
aSiT=1;
else if(romSiT==U;U)
aSiT=?;
else if(romSiT==UKU)
aSiT=10;
else if(romSiT==U4U)
aSiT=?0;
else if(romSiT==U0U)
aSiT=100;
else if(romSiT==U,U)
aSiT=?00;
else if(romSiT==U'U)
aSiT=1000;
else
{
rintf(!3n*nvalid ;alue!);
>etch();
eIit(0);
=
=
A=aSlen81T;
for(i=len81;i>0;i88)
{
if(aSiT>aSi81T)
A=A8aSi81T;
else if(aSiT==aSi81T XX aSiT<aSi81T)
A=A<aSi81T;
=
rintf(!3n*ts ,ecimal .Puivalent is5!);
rintf(!6d!,A);
>etch();
=
O'.'&
.nter the #oman +umeral5',04K*
*ts ,ecimal .Puivalent is51NN1
CP LAB MANUAL 19
WEEK 11
/* 11.a)W)i'e a C .)o-)a* '(a' !e! #nc'ion! 'o .e)#o)* '(e
#o$$o%in- o.e)a'ion!&
i) Rea"in- a co*.$e4 n*be)
ii) W)i'in- a co*.$e4 n*be)
iii) A""i'ion o# '%o co*.$e4 n*be)!
i0) M$'i.$ica'ion o# '%o co*.$e4 n*be)!
(+ote5 reresent comleI number usin> a structure.) O9
#include<stdio.h>
#include<math.h>
void arithmetic(int oern);
struct com
{
double realart;
double im>art;
=;
void main()
{
int oern;
clrscr();
rintf(!3n3n 3t3t3tOOOOO '&*+ '.+2 OOOOO!);
rintf(!3n3n 1elect Qour otion5 3n 1 5 &,,3n 2 5 '24(*"4V3n 0 5 .K*( 3n3n3t3t
.nter Qour $tion S T3b3b!);
scanf(!6d!,7oern);
sDitch(oern)
{
case 05
eIit(0);
case 15
case 25
arithmetic(oern);
default5
main();
=
=
void arithmetic(int oern)
{
struct com D1, D2, D;
rintf(!3n .nter tDo 0omleI +umbers (I<iQ)53n #eal "art of )irst +umber5!);
scanf(!6lf!,7D1.realart);
rintf(!3n *ma>inarQ "art of )irst +umber5!);
scanf(!6lf!,7D1.im>art);
rintf(!3n #eal "art of 1econd +umber5!);
scanf(!6lf!,7D2.realart);
rintf(!3n *ma>inarQ "art of 1econd +umber5!);
scanf(!6lf!,7D2.im>art);
sDitch(oern)
{
9Oaddition of comleI numberO9
case 15
D.realart = D1.realart<D2.realart;
D.im>art = D1.im>art<D2.im>art;
breaA;
9Omultilication of comleI numberO9
case 25
D.realart=(D1.realartOD2.realart)8(D1.im>artOD2.im>art);
D.im>art=(D1.realartOD2.im>art)<(D1.im>artOD2.realart);
breaA;
=
if (D.im>art>0)
rintf(!3n &nsDer = 6lf<6lfi!,D.realart,D.im>art);
else
rintf(!3n &nsDer = 6lf6lfi!,D.realart,D.im>art);
>etch();
main();
=
CP LAB MANUAL 20
O'.'&
OOOOO '&*+ '.+2 OOOOO
1elect Qour otion5
1 5 &,,
2 5 '24(*"4V
0 5 .K*(
.nter Qour $tion S 2T
.nter tDo 0omleI +umbers (I<iQ)5
#eal "art of )irst +umber52
*ma>inarQ "art of )irst +umber5@
#eal "art of 1econd +umber5?
*ma>inarQ "art of 1econd +umber5N
&nsDer = 8F.000000<2C.000000i
WEEK 11
/* W)i'e a C .)o-)a* %(ic( co.ie! one #i$e 'o ano'(e).*/
#include <stdio.h>
#include <conio.h>
#include <rocess.h>
void main(int ar>c, char Oar>vST)
{
)*4. Ofs,Oft;
char ch;
clrscr();
if(ar>cE=@)
{
uts(!*nvalid number of ar>uments.!);
eIit(0);
=
fs = foen(ar>vS1T,!r!);
if(fs==+244)
{
uts(!1ource file cannot be oened.!);
eIit(0);
=
ft = foen(ar>vS2T,!D!);
if (ft==+244)
{
uts(!(ar>et file cannot be oened.!);
fclose(fs);
eIit(0);
=
Dhile(1)
{
ch=f>etc(fs);
if (ch==.$))
breaA;
else
futc(ch,ft);
=
fclose(fs);
fclose(ft);
>etch();
=
CP LAB MANUAL 21
/* 11b)W)i'e a C .)o-)a* 'o )e0e)!e '(e #i)!' n c(a)ac'e)! in a #i$e.
=No'e& ;(e #i$e na*e an" n a)e !.eci#ie" on '(e co**an" $ine.)*/
#include <stdio.h>
#include <conio.h>
#include <strin>.h>
#include <rocess.h>
void main(int ar>c, char Oar>vST)
{
char aS1?T;
char sS20T;
char n;
int A;
int W=0;
int i;
int len;
)*4. Of;
if(ar>cE=@)
{
uts(!*mroer number of ar>uments.!);
eIit(0);
=
f = foen(ar>vS1T,!r!);
if(f == +244)
{
uts(!)ile cannot be oened.!);
eIit(0);
=
A=Oar>vS2T8MF;
n = fread(a,1,A,f);
aSnT=U30U;
len=strlen(a);
for(i=len81;i>=0;i88)
{
sSWT=aSiT;
rintf(!6c!,sSWT);
W=W<1;
=
sSW<1T=U30U;
>etch();
=
O'.'&
;(e O'.'! #o) %ee? 11.a an" 11.b can be 0ie%e" on$, in <OS
.)o*.'
WEEK 1:
/* 1:.a) W)i'e a .)o-)a* 'o c)ea'e a $inea) $in?e" $i!' in'e)ac'i0e$,
an" .)in' o' '(e $i!' an" '(e 'o'a$ n*be) o# i'e*! in '(e $i!'. */
#include <stdio.h>
#include <stdlib.h>
#define +244 0
struct linAedHlist
{
int number;
struct linAedHlist OneIt;
=;
tQedef struct linAedHlist node; 9O node tQe defined O9
main()
{
node Ohead;
void create(node O);
int count(node O);
void rint(node O);
head = (node O)malloc(siYeof(node));
CP LAB MANUAL 22
create(head);
rintf(!3n!);
rintf(head);
rintf(!3n!);
rintf(!3n+umber of items = 6d 3n!, count(head));
=
void create(node Olist)
{
rintf(!*nut a number3n!);
rintf(!(tQe 8GGG at end)5 !);
scanf(!6d!, 7list 8> number); 9O create current node O9
if(list8>number == 8GGG)
{
list8>neIt = +244;
=
else 9Ocreate neIt node O9
{
list8>neIt = (node O)malloc(siYeof(node));
create(list8>neIt); O9 #ecursion occurs O9
=
return;
=
void rint(node Olist)
{
if(list8>neIt E= +244)
{
rintf(!6d88>!,list 8>number); 9O rint current item O9

if(list8>neIt8>neIt == +244)
rintf(!6d!, list8>neIt8>number);
rint(list8>neIt); 9O move to neIt item O9
=
return;
=
int count(node Olist)
{
if(list8>neIt == +244)
return (0);
else
return(1< count(list8>neIt));
=
O'.'
*nut a number
(tQe 8GGG to end); N0
*nut a number
(tQe 8GGG to end); 20
*nut a number
(tQe 8GGG to end); 10
*nut a number
(tQe 8GGG to end); M0
*nut a number
(tQe 8GGG to end); @0
*nut a number
(tQe 8GGG to end); ?0
*nut a number
(tQe 8GGG to end); 8GGG
N0 88>20 88>10 88>M0 88>@0 88>?0 88> 8GGG
+umber of items = N
/* 1:b)W)i'e a #nc'ion #o) "e$e'in- an i'e* #)o* $in?e" $i!' */
node Odelete(node Ohead)
{
node Ofind(node O, int a);
int AeQ; 9O item to be deleted O9
node On1; 9O ointer to node recedin> AeQ node O9
node O; 9O temorarQ ointer O9
rintf(!3n :hat is the item (number) to be deletedR!);
CP LAB MANUAL 23
scanf(!6d!, 7AeQ);
if(head8>number == AeQ) 9O first node to be deleted) O9
{
= head8>neIt; 9O ointer to 2nd node in list O9
free(head); 9O release sace of AeQ node O9
head = ; 9O maAe head to oint to 1st node O9
=
else
{
n1 = find(head, AeQ);
if(n1 == +244)
rintf(!3n AeQ not found 3n!);
else 9O delete AeQ node O9
{
= n18>neIt8>neIt; 9O ointer to the node
folloDin> the AeQnode O9
free(n18>neIt); 9O free AeQ node O9
n18>neIt = ; 9O establish linA O9
=
=
return(head);
=
9O 21. )2+0(*$+ find() -.#. O9
/* W)i'e a #nc'ion #o) in!e)'in- an i'e* in'o a $in?e" $i!' */
node Oinsert(node Ohead)
{
node Ofind(node O, int a);
node OneD; 9O ointer to neD node O9
node On1; 9O ointer to node recedin> AeQ node O9
int AeQ;
int I; 9O neD item (number) to be inserted O9
rintf(!;alue of neD itemR!);
scanf(!6d!, 7I);
rintf(!;alue of AeQ item R (tQe 8GGG if last) !);
scanf(!6d!, 7AeQ);
if(head8>number == AeQ) 9O neD node is first O9
{
neD = (node O)malloc(siYe of(node));
neD8>number = I;
neD8>neIt = head;
head = neD;
=
else 9O find AeQ node and insert neD node O9
{ 9O before the AeQ node O9
n1 = find(head, AeQ); 9O find AeQ node O9
if(n1 == +244)
rintf(!3n AeQ is not found 3n!);
else 9O insert neD node O9
{
neD = (node O)malloc(siYeof(node));
neD8>number = I;

neD8>neIt = n18>neIt;
n18>neIt = neD;
=
=
return(head);
=
node Ofind(node Olists, int AeQ)
{
if(list8>neIt8>number == AeQ) 9O AeQ found O9
return(list);
else
if(list8>neIt8>neIt == +244) 9O end O9
return(+244);
CP LAB MANUAL 24
else
find(list8>neIt, AeQ);
=
/*1: c) W)i'e a .)o-)a* #o) c)ea'ion o# !o)'e" $i!' #)o* a -i0en $i!' o#
n*be)! */
#include <stdio.h>
#include <stdlib.h>
#define +244 0
struct linAedHlist
{
int number;
struct linAedHlist OneIt;
=;
tQedef struct linAedHlist node;
main ()
{
int n;
node Ohead = +244;
void rint(node O);
node OinsertH1ort(node O, int n);
rintf(!*nut the list of numbers.3n!);
rintf(!&t end, tQe 8GGG.3n!);
scanf(!6d!,7n);
Dhile(n E= 8GGG)
{
if(head == +244) 9O create UbaseU node O9
{
head = (node O)malloc(siYeof(node));
head 8>number = n;
head8>neIt = +244;
=
else 9O insert neIt item O9
{
head = insertHsort(head,n);
=
scanf(!6d!, 7n);
=
rintf(!3n!);
rint(head);
rint(!3n!);
=
node OinsertHsort(node Olist, int I)
{
node O1, O2, O;
1 = +244;
2 = list; 9O 2 oints to first node O9
for( ; 28>number < I ; 2 = 28>neIt)
{
1 = 2;
if(28>neIt == +244)
{
2 = 28>neIt; 9O 2 set to +244 O9
breaA; 9O insert neD node at end O9
=
=
9O AeQ node found O9
= (node O)malloc(siYeof(node)); 9O sace for neD node O9
8>number = I; 9O lace value in the neD node O9
8>neIt = 2; 9O linA neD node to AeQ node O9
if (1 == +244)
CP LAB MANUAL 25
list = ; 9O neD node becomes the first
node O9
else
18>neIt = ; 9O neD node inserted after
1st node O9
return (list);
=
void rint(node Olist)
{
if (list == +244)
rintf(!+244!);
else
{
rintf(!6d88>!,list8>number);
rint(list8>neIt);
=
return;
=
O'.'
*nut the list of number.
&t end, tQe 8GGG.
F0 C0 ?0 M0 N0 8GGG
M088>?088>N088>C088>F0 88>+244
*nut the list of number.
&t end, tQe 8GGG.
M0 C0 ?0 N0 F0 8GGG
M088>?088>N088>C088>F088>+244
WEEK 17
/* W)i'e a C .)o-)a* '(a' !e! #nc'ion! 'o .e)#o)* '(e #o$$o%in-
o.e)a'ion! on "ob$, $in?e" $i!'.&
i) C)ea'ion ii) In!e)'ion iii) <e$e'ion i0) ;)a0e)!a$ in bo'( %a,!
*/
#include !stdio.h!
#include !alloc.h!
tQedef struct dubll
{
int data;
struct dubll OleftlinA,Ori>htlinA;
=O,2/44;
,2/44 hi>h,temHnode,loD,last,ntr;
int fla>=0;
,2/44 +ode&lloc();
,2/44 1earch(int,int);
void 0reate*tem();
void &end*tem();
void "rint*tem();
void ,elete*tem();
,2/44 1earch(int item,int fla>);
,2/44 +ode&lloc();
void *nsert*tem();
void main(void)
{
int choice,*tem;
hi>h=+244;
Dhile(1)
{
clrscr();
rintf(!3n 3t3t3tOOOOO ' & * + ' . + 2 OOOOO3n3n!);
rintf(!3n 15 0reate 4inAed 4ist 3n 25 &end a +ode to the 4ist 3n @5 (raverse the
4ist 3n M5 ,elete a +ode from the 4ist 3n ?5 1earch a +ode 3n N5 *nsert a +ode to
the 4ist 3n C5 0lose 3n3n3t3t .nter Qour $tion S T3b3b!);
scanf(!6d!,7choice);
CP LAB MANUAL 26
sDitch(choice)
{
case 15
0reate*tem();
uts(!3n"ress anQ AeQ to >o bacA to main menu.!);
>etch();
breaA;
case 25
&end*tem();
breaA;
case @5
"rint*tem();
uts(!3n"ress anQ AeQ to >o bacA to main menu.!);
>etch();
breaA;
case M5
,elete*tem();
breaA;
case ?5
rintf(!)ind an *tem5 !);
scanf(!6d!,7*tem);
temHnode=1earch(*tem,0);
if(temHnode)
{
uts(!(he item is available in the 4inAed 4ist.!);
=
else
{
uts(!(he item is not found in the 4inAed 4ist.!);
=
>etch();
breaA;
case N5
*nsert*tem();
breaA;
case C5
eIit();
default5
uts(!*nvalid choice.!);
uts(!3n"ress anQ AeQ to >o bacA to main menu.!);
>etch();
breaA;
=
=
=
/* Fnc'ion 'o C)ea'e '(e $i!'*/
void 0reate*tem()
{
if(hi>h==+244)
{
rintf(!3n 880reatin> the list88!);
temHnode=+ode&lloc();
rintf(!3n .nter startin> data (as inte>er value) 5!);
scanf(!6d!,7temHnode8>data);
hi>h=temHnode;
=
else{ rintf(!3n 4ist alreadQ created Z 6d Dith 6d as data.!,hi>h,hi>h8>data);=
=
/* Fnc'ion 'o A..en" i'e*! 'o '(e $i!'*/
void &end*tem()
{
loD=hi>h;
if(hi>h==+244)
{
0reate*tem();
=
else
{
temHnode=+ode&lloc();
rintf(!3n .nter *tem (in inte>er) 5!);
CP LAB MANUAL 27
scanf(!6d!,7temHnode8>data);
temHnode8>ri>htlinA=+244;
Dhile(loD8>ri>htlinAE=+244)
loD=loD8>ri>htlinA;
loD8>ri>htlinA=temHnode;
temHnode8>leftlinA=loD;
last=loD8>ri>htlinA;
=
=
/* Fnc'ion 'o ;)a0e)!e '(e $i!' bo'( %a,! an" .)in' '(e "a'a*/
void "rint*tem()
{
,2/44 temHnode;
if(hi>h==+244)
{
rintf(!3n 4ist is not available. "lease create a list first.!);
>etch();
0reate*tem();
=
temHnode=hi>h;
last=loD8>ri>htlinA;
rintf(!3n88"rintin> (he 4ist *n )orDard direction883n!);
Dhile(temHnodeE=+244) 99*n forDard direction
{
rintf(!3t 6d!,temHnode8>data);
temHnode = temHnode8>ri>htlinA;
=
rintf(!3n!);
rintf(!3n88"rintin> (he 4ist *n /acADard direction883n!);
temHnode=hi>h;
if(temHnode8>ri>htlinA==+244){rintf(!6d!,temHnode8>data);return; =
Dhile(lastE=+244) 99*n bacADard direction
{
rintf(!3t 6d!,last8>data);
last = last8>leftlinA;
=
=
9O )unction to ,elete items of the listO9
void ,elete*tem()
{
int value;
,2/44 temHnode;
if(hi>h==+244)
{
rintf(!3n 4ist is not available. "lease create a list first.!);
>etch();
0reate*tem();
=
rintf(!3n *tem to delete 5!);
scanf(!6d!,7value);
ntr=1earch(value,1);
ntr8>leftlinA8>ri>htlinA=ntr8>ri>htlinA;
ntr8>ri>htlinA8>leftlinA=ntr8>leftlinA;
temHnode=ntr;
free(temHnode);
=
9O )unction to 1earch an item from the listO9
,2/44 1earch(int item,int fla>)
{
temHnode = hi>h;
if(hi>h==+244)
{
rintf(!3n 4ist is not available. "lease create a list first.!);
>etch();
0reate*tem();
=
Dhile(temHnodeE=+244)
{
if(temHnode8>data==item )
CP LAB MANUAL 28
{
if(fla>==0)
{
return(1);
=
else
{
return(temHnode);
=
=
temHnode=temHnode8>ri>htlinA;
=
=
9O )unction to &llocate nodesO9
,2/44 +ode&lloc()
{
,2/44 tmeHnode;
tmeHnode=malloc(siYeof(struct dubll));
if(tmeHnode==+244)
{
rintf(!3n +o memorQ available. +ode allocation cannot be done.!);
=
tmeHnode8>ri>htlinA=tmeHnode8>leftlinA=+244;
return(tmeHnode);
=
9O )unction to *nsert items in the middle of the listO9
void *nsert*tem()
{
int node;
,2/44 temHnode;
if(hi>h==+244)
{
rintf(!3n 4ist is not available. "lease create a list first.!);
>etch();
0reate*tem();
=
temHnode=+ode&lloc();
rintf(!"osition &t Dhich node to be inserted5 HHH 7 +eD *tem ;alue5 HHH !);
scanf(!6d!,7node);
scanf(!6d!,7temHnode8>data);
ntr=1earch(node,1);
if(ntr8>ri>htlinA==+244){rintf(!3n (he oeration is not ossible.!);
>etch();return;=
temHnode8>leftlinA=ntr; 99creatin> linA to neD node
temHnode8>ri>htlinA=ntr8>ri>htlinA;
ntr8>ri>htlinA8>leftlinA=temHnode;
ntr8>ri>htlinA=temHnode;
rintf(!3n *tem has been *nserted.!);
>etch();
=
O'.'& OOOOO ' & * + ' . + 2 OOOOO
15 0reate 4inAed 4ist
25 &end a +ode to the 4ist
@5 (raverse the 4ist
M5 ,elete a +ode from the 4ist
?5 1earch a +ode
N5 *nsert a +ode to the 4ist
C5 0lose
.nter Qour $tion S @T
88"rintin> (he 4ist *n )orDard direction88
12 ??
88"rintin> (he 4ist *n /acADard direction88
?? 12
"ress anQ AeQ to >o bacA to main menu.
CP LAB MANUAL 29
WEEK 1B
/* 1B a)W)i'e C .)o-)a*! '(a' i*.$e*en' !'ac? =i'! o.e)a'ion!)
!in- i) A))a,! */
#include<stdio.h>
#include<conio.h>
int stHarrS20T;
int t=81;
void ushHele(int ele);
int oHele();
void dislaQHele();
void main()
{
char choice,num1=0,num2=0;
Dhile(1)
{
clrscr();
rintf(!======================================!);
rintf(!3n3t3t '.+2 !);
rintf(!3n======================================!);
rintf(!3nS1T 2sin> "ush )unction!);
rintf(!3nS2T 2sin> "o )unction!);
rintf(!3nS@T .lements resent in 1tacA!);
rintf(!3nSMT .Iit3n!);
rintf(!3n3t.nter Qour choice5 !);
fflush(stdin);
scanf(!6c!,7choice);
sDitch(choice8U0U)
{
case 15
{
rintf(!3n3t.lement to be ushed5 !);
scanf(!6d!,7num1);
ushHele(num1);
breaA;
=
case 25
{
num2=oHele(1);
rintf(!3n3t.lement to be oed5 6d3n3t!,num2);
>etch();
breaA;
=
case @5
{
dislaQHele();
>etch();
breaA;
=
case M5
eIit(1);
breaA;
default5
rintf(!3nVour choice is invalid.3n!);
breaA;
=
=
=
/*I*.$e*en'in- '(e .!(=) #nc'ion. */
void ushHele(int ele)
{
if(t==GG)
{
rintf(!1(&0B is )ull.3n!);
>etch();
eIit(1);
=
stHarrS<<tT=ele;
=
9O*mlementin> the o() function. O9
int oHele()
{
int ele1;

CP LAB MANUAL 30
if(t==81)
{
rintf(!3n3t1(&0B is .mtQ.3n!);
>etch();
eIit(1);
=
return(stHarrSt88T);
=
9O*mlementin> dislaQ() function. O9
void dislaQHele()
{
int A;
rintf(!3n3t.lements resent in the stacA are53n3t!);
for(A=0;A<=t;A<<)
rintf(!6d3t!,stHarrSAT);
=
O'.'&
======================================
'.+2
======================================
S1T 2sin> "ush )unction
S2T 2sin> "o )unction
S@T .lements resent in 1tacA
SMT .Iit
.nter Qour choice5 @
.lements resent in the stacA are5
2? NG @@ ?M ?C
/* 1Bb)W)i'e C .)o-)a*! '(a' i*.$e*en' !'ac? =i'! o.e)a'ion!)
!in- ii) Poin'e)! */
#include<stdio.h>
#include<conio.h>
struct stHoint
{
int ele;
struct stHoint Ol;
=
Ot;
int i;
void ushHele(int W);
int oHele();
void dislaQHele();
void main()
{
char choice,num1=0,num2=0;
int i;
Dhile(1)
{
clrscr();
rintf(!======================================!);
rintf(!3n3t3t '.+2 !);
rintf(!3n======================================!);
rintf(!3nS1T 2sin> "ush )unction!);
rintf(!3nS2T 2sin> "o )unction!);
rintf(!3nS@T .lements resent in 1tacA!);
rintf(!3nSMT .Iit3n!);
rintf(!3n3t.nter Qour choice5 !);
fflush(stdin);
scanf(!6c!,7choice);
sDitch(choice8U0U)
{
case 15
{
rintf(!3n3t.lement to be ushed5!);
scanf(!6d!,7num1);
ushHele(num1);
breaA;
=
case 25
{
num2=oHele(1);
rintf(!3n3t.lement to be oed5 6d3n3t!,num2);
>etch();
breaA; =
CP LAB MANUAL 31
case @5
{
rintf(!3n3t.lements resent in the stacA are53n3t!);
dislaQHele();
>etch();
breaA;
=
case M5
eIit(1);
breaA;
default5
rintf(!3nVour choice is invalid.3n!);
breaA;
=
=
=
9O*nsertin> the elements usin> ush functionO9
void ushHele(int W)
{
struct stHoint Om;
m=(struct stHointO)malloc(siYeof(struct stHoint));
m8>ele=W;
m8>l=t;
t=m;
return;
=
9O#emovin> the elements usin> o functionO9
int oHele()
{
if(t==+244)
{
rintf(!3n31(&0B is .mtQ.!);
>etch();
eIit(1);
=
else
{
int i=t8>ele;
t=t8>l;
return (i);
=
return 0;
=
9O,islaQin> the elements O9
void dislaQHele()
{
struct stHoint Oointer=+244;
ointer=t;
Dhile(ointerE=+244)
{

rintf(!6d3t!,ointer8>ele);
ointer=ointer8>l;
=
=
O'.'&
======================================
'.+2
======================================
S1T 2sin> "ush )unction
S2T 2sin> "o )unction
S@T .lements resent in 1tacA
SMT .Iit
.nter Qour choice5 @
.lements resent in the stacA are5
NG MC 2@ 2?
CP LAB MANUAL 32
WEEK 18
/* 18 a)W)i'e C .)o-)a*! '(a' i*.$e*en' Iee =i'! o.e)a'ion!)
!in- i) A))a,! */
#include<stdio.h>
#include<alloc.h>
#include<conio.h>
#define siYe 10
#define true 1
#define false 0
struct PHarr
{
int f,r;
int num;
int aSsiYeT;
=;
void init(struct PHarrO Pueue);
int eHPue(struct PHarrO Pueue);
int fHPue(struct PHarrO Pueue);
int addHele(struct PHarrO Pueue,int);
int remHele(struct PHarrO Pueue);
void dislaQHele(struct PHarrO Pueue);
9Omain functionO9
void main()
{
int ele,A;
int ch;
struct PHarr OPueue = (struct PHarrO)malloc(siYeof(struct PHarr));
init(Pueue);
Dhile(1)
{
clrscr();
rintf(!3n3nOOOO*'"4.'.+(&(*$+ $) J2.2. 21*+% &##&V1OOOO3n!);
rintf(!============================================!);
rintf(!3n3t3t'.+23n!);
rintf(!============================================!);
rintf(!3n3tS1T (o insert an element!);
rintf(!3n3tS2T (o remove an element!);
rintf(!3n3tS@T (o dislaQ all the elements!);
rintf(!3n3tSMT .Iit!);
rintf(!3n3n3t .nter Qour choice5 !);
scanf(!6d!,7ch);
sDitch(ch)
{
case 15
{
rintf(!3n.lement to be inserted5!);
scanf(!6d!,7ele);
addHele(Pueue,ele);
breaA;
=
case 25
{
if(EeHPue(Pueue))
{
A=remHele(Pueue);
rintf(!3n6d element is removed3n!,A);
>etch();
=
else
{
rintf(!3tJueue is .mtQ. +o element can be removed.!);
>etch();
=
breaA;
=
case @5
{
dislaQHele(Pueue);
>etch();
breaA;
=
CP LAB MANUAL 33
case M5
eIit(0);
default5
rintf(!3t*nvalid 0hoice.!);
>etch();
breaA;
=
=
=
9Oend mainO9
void init(struct PHarrO Pueue)
{
Pueue8>f = 0;
Pueue8>r = 81;
Pueue8>num = 0;
=
/* Fnc'ion 'o c(ec? i! '(e qee i! e*.',*/
int eHPue(struct PHarrO Pueue)
{
if(Pueue8>num==0)
return true;
return false;
=
/* Fnc'ion 'o c(ec? i# '(e qee i! #$$*/
int fHPue(struct PHarrO Pueue)
{
if(Pueue8>num == siYe)
return true;
return false;
=
/* Fnc'ion 'o a"" an e$e*en' 'o '(e qee*/
int addHele(struct PHarrO Pueue,int W)
{
if(fHPue(Pueue))
return false;
if(Pueue8>r == siYe 8 1)
Pueue8>r = 81;
Pueue8>aS<<Pueue8>rT = W;
Pueue8>num<<;
return true;
=
/* Fnc'ion 'o )e*o0e an e$e*en' o# '(e qee*/
int remHele(struct PHarrO Pueue)
{
int W;
if(eHPue(Pueue))
return 8GGGG;
W = Pueue8>aSPueue8>f<<T;
if(Pueue8>f == siYe)
Pueue8>f = 0;
Pueue8>num88;
return W;
=
9O )unction to dislaQ the PueueO9
void dislaQHele(struct PHarrO Pueue)
{
int W;
if(eHPue(Pueue))
{
rintf(!Jueue is .mtQ. +o records to dislaQ.!);
return;
=
rintf(!3n.lements resent in the Jueue are5 !);
for(W=Pueue8>f;W<=Pueue8>r;W<<)
rintf(!6d3t!,Pueue8>aSWT);
rintf(!3n!);
=
CP LAB MANUAL 34
O'.'&
OOOO*'"4.'.+(&(*$+ $) J2.2. 21*+% &##&V1OOOO
============================================
'.+2
============================================
S1T (o insert an element
S2T (o remove an element
S@T (o dislaQ all the elements
SMT .Iit
.nter Qour choice5 @
.lements resent in the Jueue are5 2? ?F ?N ?C ??
/* 18 b)W)i'e C .)o-)a*! '(a' i*.$e*en' Iee =i'! o.e)a'ion!)
!in- ii) Poin'e)! */
#define true 1
#define false 0
#include<stdio.h>
#include<conio.h>
#include<rocess.h>
struct PHoint
{
int ele;
struct PHointO n;
=;
struct PHoint OfHtr = +244;
int eHPue(void);
void addHele(int);
int remHele(void);
void shoDHele();
9Omain functionO9
void main()
{
int ele,choice,W;
Dhile(1)
{
clrscr();
rintf(!3n3nOOOO*'"4.'.+(&(*$+ $) J2.2. 21*+% "$*+(.#1OOOO3n!);
rintf(!==============================================!);
rintf(!3n3t3t '.+23n!);
rintf(!==============================================!);
rintf(!3n3tS1T (o insert an element!);
rintf(!3n3tS2T (o remove an element!);
rintf(!3n3tS@T (o dislaQ all the elements!);
rintf(!3n3tSMT .Iit!);
rintf(!3n3n3t.nter Qour choice5!);
scanf(!6d!, 7choice);
sDitch(choice)
{
case 15
{
rintf(!3n3t.lement to be inserted5!);
scanf(!6d!,7ele);
addHele(ele);
>etch();
breaA;
=
case 25
{
if(EeHPue())
{
W=remHele();
rintf(!3n3t6d is removed from the Pueue!,W);
>etch();
=
else
{
rintf(!3n3tJueue is .mtQ.!);
>etch();
=
breaA; =
CP LAB MANUAL 35
case @5
shoDHele();
>etch();
breaA;
case M5
eIit(1);
breaA;
default5
rintf(!3n3t*nvalid choice.!);
>etch();
breaA;
=
=
=
/* Fnc'ion 'o c(ec? i# '(e qee i! e*.',*/
int eHPue(void)
{
if(fHtr==+244)
return true;
return false;
=
/* Fnc'ion 'o a"" an e$e*en' 'o '(e qee*/
void addHele(int ele)
{
struct PHoint OPueue = (struct PHointO)malloc(siYeof(struct PHoint));
Pueue8>ele = ele;
Pueue8>n = +244;
if(fHtr==+244)
fHtr = Pueue;
else
{
struct PHointO tr;
tr = fHtr;
for(tr=fHtr ;tr8>nE=+244; tr=tr8>n);
tr8>n = Pueue;
=
=
9O )unction to remove an element from the PueueO9
int remHele()
{
struct PHointO Pueue=+244;
if(eHPue()==false)
{
int W = fHtr8>ele;
Pueue=fHtr;
fHtr = fHtr8>n;
free (Pueue);
return W;
=
else
{
rintf(!3n3tJueue is emtQ.!);
return 8GGGG;
=
=
9O )unction to dislaQ the PueueO9
void shoDHele()
{
struct PHoint Otr=+244;
tr=fHtr;
if(eHPue())
{
rintf(!3n3tJ2.2. is .mtQ.!);
return;
=
else
{
rintf(!3n3t.lements resent in Jueue are53n3t!);

CP LAB MANUAL 36
Dhile(trE=+244)
{
rintf(!6d3t!,tr8>ele);
tr=tr8>n;
=
=
=
O'.'&
OOOO*'"4.'.+(&(*$+ $) J2.2. 21*+% "$*+(.#1OOOO
==============================================
'.+2
==============================================
S1T (o insert an element
S2T (o remove an element
S@T (o dislaQ all the elements
SMT .Iit
.nter Qour choice5@
.lements resent in Jueue are5
22 22 @@ @?
WEEK 1C
/* 1C a) W)i'e a C .)o-)a* '(a' !e! S'ac? o.e)a'ion! 'o .e)#o)* '(e
#o$$o%in-&
i) Con0e)'in- in#i4 e4.)e!!ion in'o .o!'#i4 e4.)e!!ion
ii) E0a$a'in- '(e .o!'#i4 e4.)e!!ion */
#include<stdio.h>
#include<conio.h>
int stS100T;
int stHto=81;
int cal(char ostST);
void inHost(char inST);
void ushHitem(int it);
int oHitem();
int stH*1"(char t);
int stH*0"(char t);
9Omain functionO9
void main()
{
char inS100T,ostS100T;
clrscr();
rintf(!3n3t.nter the *nfiI .Iression5 !);
>ets(in);
inHost(in);
>etch();
=
9Oend mainO9
void ushHitem(int it)
{
if(stHto==GG)
{
rintf(!3n3n3tO1(&0B is )ullO!);
>etch();
eIit(1);
=
stS<<stHtoT=it;
=
int oHitem()
{
int it;
if(stHto==81)
{
CP LAB MANUAL 37
>etch();
=
return(stSstHto88T);
=
9O)unction for convertin> an infiI eIression to a ostfiI eIression. O9
void inHost(char inST)
{
int I=0,Q=0,Y,result=0;
char a,c, ostS100T;
char t;
ushHitem(U30U);
t=inSIT;
Dhile(tE=U30U)
{
if(isalnum(t))
9O)or checAin> Dhether the value in t is an alhabet or number. O9
{
ostSQT=t;
Q<<;
=
else if(t==U(U)
{
ushHitem(U(U);
=
else if(t==U)U)
{
Dhile(stSstHtoTE=U(U)
{
c=oHitem();
ostSQT=c;
Q<<;
=
c=oHitem();
=
else
{
Dhile(stH*1"(stSstHtoT)>=stH*0"(t))
{
c=oHitem();
ostSQT=c;
Q<<;
=
ushHitem(t);
=
I<<;
t=inSIT;
=
Dhile(stHtoE=81)
{
c=oHitem();
ostSQT=c;
Q<<;
=
rintf(!3n3t(he "ostfiI .Iression is5!);

for(Y=0;Y<Q;Y<<)
rintf(!6c!,ostSYT);
rintf(!3n3n,o Qou Dant to evaluate the #esult of "ostfiI .IressionR(V9+)5!);
scanf(!6c!,7a);
if(a==UQU XX a==UVU)
{
result=cal(ost);
rintf(!3n3n3t#esult is5 6d3n!,result);
>etch();
=
else if(a==UnU XX a==U+U)
{
eIit(0);
=
=
CP LAB MANUAL 38
/*<e'e)*inin- .)io)i', o# in!i"e e$e*en'!*/
int stH*1"(char t)
{
sDitch(t)
{
case U(U5return (10);
case U)U5return (G);
case U<U5return (C);
case U8U5return (C);
case UOU5return (F);
case U9U5return (F);
case U30U5return (0);
default5 rintf(!.Iression is invalid.!);
breaA;
=
return 0;
=
/*<e'e)*inin- .)io)i', o# a..)oac(in- e$e*en'!*/
int stH*0"(char t)
{
sDitch(t)
{
case U(U5return (10);
case U)U5return (G);
case U<U5return (C);
case U8U5return (C);
case UOU5return (F);
case U9U5return (F);
case U30U5return (0);
default5 rintf(!.Iression is invalid.!);
breaA;
=
return 0;
=
9O.valuatin> the result of ostfiI eIressionO9
int cal(char ostST)
{
int m,n,I,Q,W=0,len;
len=strlen(ost);
Dhile(W<len)
{
if(isdi>it(ostSWT))
{
I=ostSWT8U0U;
ushHitem(I);
=
else
{
m=oHitem();
n=oHitem();
sDitch(ostSWT)
{
case U<U5I=n<m;
breaA;
case U8U5I=n8m;
breaA;
case UOU5I=nOm;
breaA;
case U9U5I=n9m;
breaA;
=
ushHitem(I);
=
W<<;
=
if(stHto>0)
{
rintf(!+umber of $erands are more than $erators.!);
eIit(0);
=
else
{
Q=oHitem();

CP LAB MANUAL 39
return (Q);
=
return 0;
=
O'.'&
.nter the *nfiI .Iression5 1<2O@8M9?<NOC8M
(he "ostfiI .Iression is512@O<M?98NCO<M8
,o Qou Dant to evaluate the #esult of "ostfiI .IressionR(V9+)5Q
#esult is5 M?
WEEK 19
/* W)i'e a C .)o-)a* '(a' !e! #nc'ion! 'o .e)#o)* '(e #o$$o%in-&
i) C)ea'in- a Bina), ;)ee o# in'e-e)!
ii) ;)a0e)!in- '(e abo0e bina), ')ee in .)eo)"e)/ ino)"e) an"
.o!'o)"e). */
#include<stdio.h>
#include <stdlib.h>
#include<conio.h>
struct treenode
{
int ele;
struct treenode OlHchild, OrHchild;
=;
struct treenode OinsertHnode(struct treenode Ot,int a);
void (raverse*norder(struct treenode Ot);
void (raverse"reorder(struct treenode Ot);
void (raverse"ostorder(struct treenode Ot);
9Omain functionO9
void main()
{
struct treenode OrootHnode = +244;
int num,value;
int choice;
clrscr();
rintf(!88888888888888888888888888888888888888888888888888883n!);
rintf(!3t3t3t'.+23n!);
rintf(!888888888888888888888888888888888888888888888888888883n!);
rintf(!S1T 0reate a /inarQ (ree and 2se *norder (raversal3n!);
rintf(!S2T 0reate a /inarQ (ree and 2se "reorder (raversal3n!);
rintf(!S@T 0reate a /inarQ (ree and 2se "ostorder (raversal3n!);
rintf(!888888888888888888888888888888888888888888888888888883n!);
rintf(!.nter Qour choice5!);
scanf(!6d!,7choice);
if(choice>0 7 choice<=@)
{
rintf(!3n.nter the number of nodes5!);
scanf(!6d!,7num);
Dhile(num88 > 0)
{
rintf(!3n3n.nter the data value5!);
scanf(!6d!,7value);
rootHnode = insertHnode(rootHnode,value);
=
sDitch(choice)
{
case 15
rintf(!3n3n/inarQ tree usin> *norder (raversal 5 !);
(raverse*norder(rootHnode);
>etch();
breaA;
case 25
rintf(!3n3n/inarQ tree usin> "reorder (raversal 5 !);
(raverse"reorder(rootHnode);
>etch();
breaA;

CP LAB MANUAL 40
case @5
rintf(!3n3n/inarQ tree usin> "ostorder (raversal 5 !);
(raverse"ostorder(rootHnode);
>etch();
breaA;
default5
rintf(!*nvalid 0hoice!);
breaA;
=
=
=
9Oend mainO9
9O )unction to create a /inarQ (ree of inte>ers data O9
struct treenode OinsertHnode(struct treenode Ot,int a)
{
struct treenode OtemHnode1,OtemHnode2;
if(t == +244)
{
t = (struct treenode O) malloc(siYeof(struct treenode));
if(t == +244)
{
rintf(!;alue cannot be allocated.3n!);
eIit(0);
=
t8>ele = a;
t8>lHchild=t8>rHchild=+244;
=
else
{
temHnode1 = t;
Dhile(temHnode1 E= +244)
{
temHnode2 = temHnode1;
if( temHnode1 8>ele > a)
temHnode1 = temHnode18>lHchild;
else
temHnode1 = temHnode18>rHchild;
=
if( temHnode28>ele > a)
{
temHnode28>lHchild = (struct treenodeO)malloc(siYeof(struct treenode));
temHnode2 = temHnode28>lHchild;
if(temHnode2 == +244)
{
rintf(!;alue cannot be allocated.3n!);
eIit(0);
=
temHnode28>ele = a;
temHnode28>lHchild=temHnode28>rHchild = +244;
=
else
{
temHnode28>rHchild = (struct treenodeO)malloc(siYeof(struct treenode));
temHnode2 = temHnode28>rHchild;
if(temHnode2 == +244)
{
rintf(!;alue cannot be allocated.3n!);
eIit(0);
=
temHnode28>ele = a;
temHnode28>lHchild=temHnode28>rHchild = +244;
=
=
return(t);
=
CP LAB MANUAL 41
9O )unction for (raversin> the binarQ tree in inorder. O9
void (raverse*norder(struct treenode Ot)
{
if(t E= +244)
{
(raverse*norder(t8>lHchild);
rintf(!6d3t!,t8>ele);
inHorder(t8>rHchild);
=
=
9O )unction for (raversin> the binarQ tree in reorder. O9
void (raverse"reorder(struct treenode Ot)
{
if(t E= +244)
{
rintf(!6d3t!,t8>ele);
(raverse"reorder(t8>lHchild);
(raverse"reorder(t8>rHchild);
=
=
/* Fnc'ion #o) ;)a0e)!in- '(e bina), ')ee in .o!'o)"e). */
void (raverse"ostorder(struct treenode Ot)
{
if(t E= +244)
{
(raverse"ostorder(t8>lHchild);
(raverse"ostorder(t8>rHchild);
rintf(!6d3t!,t8>ele);
=
=
O'.'&
8888888888888888888888888888888888888888888888888888
'.+2
88888888888888888888888888888888888888888888888888888
S1T 0reate a /inarQ (ree and 2se *norder (raversal
S2T 0reate a /inarQ (ree and 2se "reorder (raversal
S@T 0reate a /inarQ (ree and 2se "ostorder (raversal
88888888888888888888888888888888888888888888888888888
.nter Qour choice51
.nter the number of nodes5G
.nter the data value512
.nter the data value5?F
.nter the data value5MC
.nter the data value5NG
.nter the data value5@?
WEEK 1D
/* 1D a) W)i'e C .)o-)a*! '(a' !e bo'( )ec)!i0e an" non )ec)!i0e
#nc'ion! 'o .e)#o)* '(e #o$$o%in- !ea)c(in- o.e)a'ion! #o) a Ke,
0a$e in a -i0en $i!' o# in'e-e)! &
i) Bina), !ea)c(*/
#include <stdio.h>
#define '&KH4.+ 10
9O +on8#ecursive functionO9
void bHsearchHnonrecursive(int lST,int num,int ele)
{
int l1,i,W, fla> = 0;
l1 = 0;
i = num81;
Dhile(l1 <= i)
{
W = (l1<i)92;
if( lSWT == ele)
{
rintf(!3n(he element 6d is resent at osition 6d in list3n!,ele,W);
fla> =1;
breaA;
=

CP LAB MANUAL 42
else
if(lSWT < ele)
l1 = W<1;
else
i = W81;
=
if( fla> == 0)
rintf(!3n(he element 6d is not resent in the list3n!,ele);
=
9O #ecursive functionO9
int bHsearchHrecursive(int lST,int arraQ1tart,int arraQ.nd,int a)
{
int m,os;
if (arraQ1tart<=arraQ.nd)
{
m=(arraQ1tart<arraQ.nd)92;
if (lSmT==a)
return m;
else if (a<lSmT)
return bHsearchHrecursive(l,arraQ1tart,m81,a);
else
return bHsearchHrecursive(l,m<1,arraQ.nd,a);
=
return 81;
=
void readHlist(int lST,int n)
{
int i;
rintf(!3n.nter the elements53n!);
for(i=0;i<n;i<<)
scanf(!6d!,7lSiT);
=
void rintHlist(int lST,int n)
{
int i;
for(i=0;i<n;i<<)
rintf(!6d3t!,lSiT);
=
9Omain functionO9
void main()
{
int lS'&KH4.+T, num, ele,f,l1,a;
int ch,os;
clrscr();
rintf(!================================================
======!);
rintf(!3n3t3t3t'.+2!);

rintf(!3n===============================================
======!);
rintf(!3nS1T /inarQ 1earch usin> #ecursion method!);
rintf(!3nS2T /inarQ 1earch usin> +on8#ecursion method!);
rintf(!3n3n.nter Qour 0hoice5!);
scanf(!6d!,7ch);
if(ch<=2 7 ch>0)
{
rintf(!3n.nter the number of elements 5 !);
scanf(!6d!,7num);
readHlist(l,num);
rintf(!3n.lements resent in the list are53n3n!);
rintHlist(l,num);
rintf(!3n3n.nter the element Qou Dant to search53n3n!);
scanf(!6d!,7ele);
sDitch(ch)
{
case 15rintf(!3n#ecursive method53n!);
os=bHsearchHrecursive(l,0,num,ele);
if(os==81)
{
rintf(!.lement is not found!);
=
CP LAB MANUAL 43

else
{
rintf(!.lement is found at 6d osition!,os);
=
>etch();
breaA;
case 25rintf(!3n+on8#ecursive method53n!);
bHsearchHnonrecursive(l,num,ele);
>etch();
breaA;
=
=>etch();=
O'.'&
====================================================
'.+2
====================================================
S1T /inarQ 1earch usin> #ecursion method
S2T /inarQ 1earch usin> +on8#ecursion method
.nter Qour 0hoice51
.nter the number of elements 5 F
.nter the elements5
M?
CF
12
@N
MF
C?
GN
@2
.lements resent in the list are5
M? CF 12 @N MF C? GN @2
.nter the element Qou Dant to search5
M?
#ecursive method5
.lement is found at 0 osition
/* 1Db)W)i'e C .)o-)a*! '(a' !e bo'( )ec)!i0e an" non )ec)!i0e
#nc'ion!
'o .e)#o)* '(e #o$$o%in- !ea)c(in- o.e)a'ion #o) a Ke, 0a$e in a
-i0en $i!' o# in'e-e)! &
ii) Linea) !ea)c( */
#include <stdio.h>
#define '&KH4.+ 10
void lHsearchHrecursive(int lST,int num,int ele);
void lHsearch(int lST,int num,int ele);
void readHlist(int lST,int num);
void rintHlist(int lST,int num);
void main()
{
int lS'&KH4.+T, num, ele;
int ch;
clrscr();
rintf(!================================================
======!);
rintf(!3n3t3t3t'.+2!);
rintf(!3n===============================================
======!);
rintf(!3nS1T 4inarQ 1earch usin> #ecursion method!);
rintf(!3nS2T 4inarQ 1earch usin> +on8#ecursion method!);
rintf(!3n3n.nter Qour 0hoice5!);
scanf(!6d!,7ch);
CP LAB MANUAL 44
if(ch<=2 7 ch>0)
{
rintf(!.nter the number of elements 5!);
scanf(!6d!,7num);
readHlist(l,num);
rintf(!3n.lements resent in the list are53n3n!);
rintHlist(l,num);
rintf(!3n3n.lement Qou Dant to search53n3n!);
scanf(!6d!,7ele);
sDitch(ch)
{
case 15rintf(!3nOO#ecursion methodOO3n!);
lHsearchHrecursive(l,num,ele);
>etch();
breaA;
case 25rintf(!3nOO+on8#ecursion methodOO3n!);
lHsearchHnonrecursive(l,num,ele);
>etch();
breaA;
=

=
>etch();
=
9Oend mainO9
9O +on8#ecursive methodO9
void lHsearchHnonrecursive(int lST,int num,int ele)
{
int W, f=0;
for(W=0;W<num;W<<)
if( lSWT == ele)
{
rintf(!3n(he element 6d is resent at osition 6d in list3n!,ele,W);
f=1;
breaA;
=
if(f==0)
rintf(!3n(he element is 6d is not resent in the list3n!,ele);
=
9O #ecursive methodO9
void lHsearchHrecursive(int lST,int num,int ele)
{
int f = 0;
if( lSnumT == ele)
{
rintf(!3n(he element 6d is resent at osition 6d in list3n!,ele,num);
f=1;
=
else
{
if((num==0) 77 (f==0))
{
rintf(!(he element 6d is not found.!,ele);
=
else
{
lHsearch(l,num81,ele);
=
=
>etch();
=
void readHlist(int lST,int num)
{
int W;
rintf(!3n.nter the elements53n!);
for(W=0;W<num;W<<)
scanf(!6d!,7lSWT); =
CP LAB MANUAL 45
void rintHlist(int lST,int num)
{
int W;

for(W=0;W<num;W<<)
rintf(!6d3t!,lSWT);
=
O'.'&
====================================================
'.+2
====================================================
S1T 4inarQ 1earch usin> #ecursion method
S2T 4inarQ 1earch usin> +on8#ecursion method
.nter Qour 0hoice51
.nter the number of elements 5?
.nter the elements5
M?
2@
MC
FG
?N
.lements resent in the list are5
M? 2@ MC FG ?N
.lement Qou Dant to search5
2@
OO#ecursion methodOO
(he element 2@ is resent at osition 1 in list

WEEK 1+
/* 1+.a)W)i'e C .)o-)a*! '(a' i*.$e*en' '(e #o$$o%in- !o)'in-
*e'(o"! 'o !o)' a -i0en $i!' o# in'e-e)! in a!cen"in- o)"e)& i) Bbb$e
!o)' */
#include <stdio.h>
#define '&K 10
void sDa4ist(int Om,int On)
{
int tem;
tem = Om;
Om = On;
On = tem;
=
99 )unction for /ubble 1ort
void bubHsort(int listST, int n)
{
int i,W;
for(i=0;i<(n81);i<<)
for(W=0;W<(n8(i<1));W<<)
if(listSWT > listSW<1T)
sDa4ist(7listSWT,7listSW<1T);
=
void readlist(int listST,int n)
{
int W;
rintf(!3n.nter the elements5 3n!);
for(W=0;W<n;W<<)
scanf(!6d!,7listSWT);
=
CP LAB MANUAL 46
99 1hoDin> the contents of the list
void rintlist(int listST,int n)
{
int W;
for(W=0;W<n;W<<)
rintf(!6d3t!,listSWT);
=
void main()
{
int listS'&KT, num;
clrscr();
rintf(!3n3n3nOOOOO .nter the number of elements S'aIimum 10T OOOOO3n!);
scanf(!6d!,7num);
readlist(list,num);
rintf(!3n3n.lements in the list before sortin> are53n!);
rintlist(list,num);
bubHsort(list,num);
rintf(!3n3n.lements in the list after sortin> are53n!);
rintlist(list,num);
>etch(); =
O'.'&
OOOOO .nter the number of elements S'aIimum 10T OOOOO
C
.nter the elements5
M
?
1
2@
M?
N@
FN
.lements in the list before sortin> are5
M ? 1 2@ M? N@ FN
.lements in the list after sortin> are5
1 M ? 2@ M? N@ FN

/* 1+ b)W)i'e C .)o-)a* '(a' i*.$e*en' '(e #o$$o%in- !o)'in-
*e'(o"!
'o !o)' a -i0en $i!' o# in'e-e)! in a!cen"in- o)"e)& ii) Iic? !o)' */
#include <stdio.h>
#define '&K 10
void sDa(int Om,int On)
{
int tem;
tem = Om;
Om = On;
On = tem;
=
int >etHAeQHosition(int I,int Q )
{
return((I<Q) 92);
=
99 )unction for JuicA 1ort
void PuicAsort(int listST,int m,int n)
{
int AeQ,i,W,A;
if( m < n)
{
A = >etHAeQHosition(m,n);
sDa(7listSmT,7listSAT);
AeQ = listSmT;
i = m<1;
W = n;
Dhile(i <= W)
{
Dhile((i <= n) 77 (listSiT <= AeQ))
i<<;
Dhile((W >= m) 77 (listSWT > AeQ))
W88;
CP LAB MANUAL 47
if( i < W)
sDa(7listSiT,7listSWT);
=
sDa(7listSmT,7listSWT);
PuicAsort(list,m,W81);
PuicAsort(list,W<1,n);
=
=
99 )unction to read the data
void readHdata(int listST,int n)
{
int W;
rintf(!3n3n.nter the elements53n!);
for(W=0;W<n;W<<)
scanf(!6d!,7listSWT);
=
99 )unction to rint the data
void rintHdata(int listST,int n)
{
int W;
for(W=0;W<n;W<<)
rintf(!6d3t!,listSWT);
=
void main()
{
int listS'&KT, num;
clrscr();
rintf(!3nOOOOO .nter the number of elements 'aIimum S10T OOOOO3n!);
scanf(!6d!,7num);
readHdata(list,num);
rintf(!3n3n.lements in the list before sortin> are53n!);
rintHdata(list,num);
PuicAsort(list,0,num81);
rintf(!3n3n.lements in the list after sortin> are53n!);
rintHdata(list,num);
>etch();
=
O'.'&
OOOOO .nter the number of elements 'aIimum S10T OOOOO
F
.nter the elements5
CF GF N? M? ?N M2 N@ M2
.lements in the list before sortin> are5
CF GF N? M? ?N M2 N@ M2
.lements in the list after sortin> are5
M2 M2 M? ?N N@ N? CF GF
WEEK 11
/* 11a)W)i'e C .)o-)a* '(a' i*.$e*en' '(e #o$$o%in- !o)'in-
*e'(o"!
'o !o)' a -i0en $i!' o# in'e-e)! in a!cen"in- o)"e)&
i) In!e)'ion !o)' */
#include<stdio.h>
#include<conio.h>
void instHsort(int ST);
void main()
{
int numS?T,count;
clrscr();
rintf(!3n.nter the )ive .lements to sort53n!);
for (count=0;count<?;count<<)
scanf(!6d!,7numScountT);
instHsort(num);
rintf(!3n3n.lements after sortin>5 3n!);
for(count=0;count<?;count<<)
rintf(!6d3n!,numScountT);
CP LAB MANUAL 48
>etch();
=
99 )unction for *nsertion 1ortin>
void instHsort(int numST)
{
int i,W,A;
for(W=1;W<?;W<<)
{
A=numSWT;
for(i=W81;i>=0 77 A<numSiT;i88)
numSi<1T=numSiT;
numSi<1T=A;
=
=
O'.'&
.nter the elements to be sorted5
F? CG NM ?@ M2 12 N@ CF FG ?N
/efore 5 F? CG NM ?@ M2 12 N@ CF FG ?N
&fter 'er>e 1ort 5 12 M2 53 56 63 64 78 79 85 89
/* 11b) W)i'e C .)o-)a* '(a' i*.$e*en' '(e #o$$o%in- !o)'in-
*e'(o"! 'o !o)' a -i0en $i!' o# in'e-e)! in a!cen"in- o)"e)&
ii) Me)-e !o)' */
#include <stdio.h>
#include <stdlib.h>
#define '&KH&#V 10
void mer>eHsort(int IST, int end, int start);
int main(void) {
int arQS'&KH&#VT;
int W = 0;
rintf(!3n3n.nter the elements to be sorted5 3n!);
for(W=0;W<'&KH&#V;W<<)
scanf(!6d!,7arQSWT);
9O arraQ before mer>esort O9
rintf(!/efore 5!);
for(W = 0; W < '&KH&#V; W<<)
rintf(! 6d!, arQSWT);
rintf(!3n!);
mer>eHsort(arQ, 0, '&KH&#V 8 1);
9O arraQ after mer>esort O9
rintf(!&fter 'er>e 1ort 5!);
for(W = 0; W < '&KH&#V; W<<)
rintf(! 6d!, arQSWT);
rintf(!3n!);
>etch();
=
9O 'ethod to imlement 'er>e 1ortO9
void mer>eHsort(int IST, int end, int start) {
int W = 0;
const int siYe = start 8 end < 1;
int mid = 0;
int mr>1 = 0;
int mr>2 = 0;
int eIecutin>S'&KH&#VT;
if(end == start)
return;
mid = (end < start) 9 2;
mer>eHsort(I, end, mid);
mer>eHsort(I, mid < 1, start);
for(W = 0; W < siYe; W<<)
eIecutin>SWT = ISend < WT;
mr>1 = 0;
mr>2 = mid 8 end < 1;
for(W = 0; W < siYe; W<<) {
if(mr>2 <= start 8 end)
if(mr>1 <= mid 8 end)
if(eIecutin>Smr>1T > eIecutin>Smr>2T)
ISW < endT = eIecutin>Smr>2<<T;
else
ISW < endT = eIecutin>Smr>1<<T;
else
ISW < endT = eIecutin>Smr>2<<T;
else
ISW < endT = eIecutin>Smr>1<<T;
= =
CP LAB MANUAL 49
O'.'&
.nter the elements to be sorted5
C F M ? N 1 2 @ 1 G
/efore 5 C F M ? N 1 2 @ 1 G
&fter 'er>e 1ort 5 1 1 2 @ M ? N C F G
WEEK 11
/*11 a) W)i'e C .)o-)a* 'o i*.$e*en' '(e La-)an-e
in'e).o$a'ion.*/
#include<stdio.h>
#include<conio.h>
#define 'aI+ G0
void main()
{
float arrHIS'aI+<1T, arrHQS'aI+<1T, numerator, denominator, I, Q=0;
int i, W, n;
clrscr();
rintf(!.nter the value of n5 3n!);
scanf(!6d!, 7n);
rintf(!.nter the values of I and Q5 3n!);
for(i=0; i<=n; i<<)
scanf(!6f6f!, 7arrHISiT, 7arrHQSiT);
rintf(!.nter the value of I at Dhich value of Q is to be calculated5 !);
scanf(!6f!, 7I);
for (i=0; i<=n; i<<)
{
numerator=1;
denominator=1;
for (W=0; W<=n; W<<)
if(WE=i)
{
numerator O= I8arrHISWT;
denominator O= arrHISiT8arrHISWT;
=
Q<=(numerator9denominator)OarrHQSiT;
=
rintf(!:hen I=6M.1f Q=6C.1f3n!,I,Q);
>etch();
=
O'.'&
.nter the value of n5
@
.nter the values of I and Q5
M.? M.2 ?.C N 2 @.0 ?.1 M.G
.nter the value of I at Dhich value of Q is to be calculated5 ?.1
:hen I= ?.1 Q= M.G
/*11 b) W)i'e C .)o-)a* 'o i*.$e*en' '(e Ne%'on3 G)e-o),
#o)%a)" in'e).o$a'ion.*/
#include<stdio.h>
#include<conio.h>
#define 'aI+ 100
#define $rderHofHdiff M
void main ()
{
float arrHIS'aI+<1T, arrHQS'aI+<1T, numerator=1.0, denominator=1.0, I, Q, , h,
diffHtableS'aI+<1TS$rderHofHdiff<1T;
int i,W,n,A;
clrscr();
rintf(!.nter the value of n 3n!);
scanf(!6d!,7n);
rintf(!.nter the values of I and Q!);
for(i=0; i<=n; i<<)
scanf(!6f6f!, 7arrHISiT, 7arrHQSiT);
rintf(!.nter the value of I at Dhich value of Q is to be calculated!);
scanf(!6f!, 7I);
h=arrHIS1T8arrHIS0T;
for(i=0; i<=n81; i<<)
diffHtableSiTS1T=arrHQSi<1T8arrHQSiT;9O0reatin> the difference table and calculatin>
CP LAB MANUAL 50
first order differencesO9
for(W=2; W<=$rderHofHdiff; W<<)9O0alculatin> hi>her order differencesO9
for(i=0; i<=n8W; i<<)
diffHtableSiTSWT=diffHtableSi<1TSW81T 8 diffHtableSiTSW81T;
i=0;
Dhile(E(arrHISiT>I)) 9O )indin> I0 O9
i<<;
i88;
=(I8arrHISiT)9h;
Q=arrHQSiT;
for (A=1; A<=$rderHofHdiff; A<<)
{
numerator O=8A<1;
denominator O=A;
Q <=(numerator9denominator)OdiffHtableSiTSAT;
=
rintf(!:hen I=6N.1f, Q=6N.2f3n!,I, Q);
>etch();
=
O'.'&
.nter the value of n
?
.nter the values of I and QM.@
?.N M.2 M.@ 1.@ 2.@ N.@ ?.M ?.1 C.? N.2 M.@
.nter the value of I at Dhich value of Q is to be calculated?.N
:hen I= ?.N, Q=C1GG22G.?0
WEEK 1:
/* 1:.a)W)i'e C .)o-)a* 'o i*.$e*en' '(e $inea) )e-)e!!ion
a$-o)i'(*. */
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<strin>.h>
float mean(float Oa, int n);
void deviation(float Oa, float mean, int n, float Od, float O1);
void main()
{
float aS20T,bS20T,dIS20T,dQS20T;
float sQ=0,sI=0,meanHI=0,meanHQ=0,sumHIQ=0;
float corrHcoff=0,re>HcoffHIQ=0, re>HcoffHQI=0;
char tQeHcoffSCT;
int n=0,i=0;
clrscr();
rintf(!.nter the value of n5 !);
scanf(!6d!,7n);
rintf(!.nter the values of I and Q53n!);
for(i=0;i<n;i<<)
scanf(!6f6f!,7aSiT,7bSiT);
meanHI=mean(a,n);
meanHQ=mean(b,n);
deviation(a,meanHI,n,dI,7sI);
deviation(b,meanHQ,n,dQ,7sQ);

for(i=0;i<n;i<<)
sumHIQ=sumHIQ<dISiTOdQSiT;
corrHcoff=sumHIQ9(nOsIOsQ);
rintf(!.nter the tQe of re>ression coefficient as UI on QU or UQ on IU5 !);
fflush(stdin);
>ets(tQeHcoff);
if(strcm(tQeHcoff,!I on Q!)==1)
{
re>HcoffHIQ=corrHcoffO(sI9sQ);
rintf(!3n(he value of linear re>ression coefficient is 6f!,re>HcoffHIQ);
=
else if(strcm(tQeHcoff,!Q on I!)==1)
{
re>HcoffHQI=corrHcoffO(sQ9sI);
rintf(!3n(he value of linear re>ression coefficient is 6f!,re>HcoffHQI);
=
CP LAB MANUAL 51
else
rintf(!3n.nter the correct tQe of re>ression coefficient.!);
>etch();
=
float mean(float Oa, int n)
{
float sum=0, i=0;
for(i=0;i<n;i<<)
sum=sum<aSiT;
sum=sum9n;
return (sum);
=
void deviation(float Oa, float mean, int n, float Od, float Os)
{
float sum=0,t=0;
int i=0;
for(i=0;i<n;i<<)
{
dSiT=aSiT8mean;
t=dSiTOdSiT;
sum=sum<t;
=
sum=sum9n;
Os=sPrt(sum);
=
O'.'&
.nter the value of n5 ?
.nter the values of I and Q5
C F G M ? N @ 2 1 C
.nter the tQe of re>ression coefficient as UI on QU or UQ on IU5 Q on I
(he value of linear re>ression coefficient is 1.0120000
WEEK 17
/* 17a) C .)o-)a* 'o i*.$e*en' Si*.!on *e'(o". */
#include<stdio.h>
#include<conio.h>
#include<math.h>
char ostfiISF0T;
float stacASF0T;
char stacA1SF0T;
int to=81,to1=81;
float eval(char ostfiIST, float I1);
void infiIHostfiI(char infiIST);
main()
{
float I0, In, h, s,e1,e2, e@;
char eISF0T, arrSF0T;
int i,n,l=0;
clrscr();
rintf(!3n.nter an eIression5 !);
>ets(eI);
uts(!.nter I0, In and number of sub8intervals5 !);
scanf(!6f6f6d!, 7I0, 7In, 7n);
h=(In8I0)9n;
if(eIS0T==UlU77 eIS1T==UoU77 eIS2T==U>U)
{
l=strlen(eI);
for(i=0;i<l8@; i<<)
arrS0T=eISi<@T;
arrSiT=U30U;
infiIHostfiI(arr);
e1=eval(ostfiI,I0);
e2=eval(ostfiI,In);
e@=MOeval(ostfiI, I0<h);
s=lo>(e1)<lo>(e2)<lo>(e@);
for (i=@;i<=n81;i<=2)
s<=MOeval(ostfiI,I0<iOh)<2Oeval(ostfiI, I0<(i81)Oh);
=
else
{
infiIHostfiI(eI);
CP LAB MANUAL 52
s=eval(ostfiI,I0)<eval(ostfiI,In)<MOeval(ostfiI, I0<h);
for (i=@;i<=n81;i<=2)
s<=MOeval(ostfiI,I0<iOh)<2Oeval(ostfiI, I0<(i81)Oh);
=
rintf(!(he value of inte>ral is 6N.@f3n!,(h9@)Os);
return(0);
=
9O*nsertin> the oerands in a stacA. O9
void ush(float item)
{
if(to==GG)
{
rintf(!3n3t(he stacA is full!);
>etch();
eIit(0);
=
else
{
to<<;
stacAStoT=item;
=
return;
=
/*Re*o0in- '(e o.e)an"! #)o* a !'ac?. */
float o()
{
float item;
if(to==81)
{
rintf(!3n3t(he stacA is emtQ3n3t!);
>etch();
=
item=stacAStoT;
to88;
return (item);
=
void ush1(char item)
{
if(to1==CG)
{
rintf(!3n3t(he stacA is full!);
>etch();
eIit(0);
=
else
{
to1<<;
stacA1Sto1T=item;
=
return;
=
9O#emovin> the oerands from a stacA. O9
char o1()
{
char item;
if(to1==81)
{
rintf(!3n3t(he stacA1 is emtQ3n3t!);
>etch();
=
item=stacA1Sto1T;
to188;
return (item);
=
/*Con0e)'in- an in#i4 e4.)e!!ion 'o a .o!'#i4 e4.)e!!ion. */
void infiIHostfiI(char infiIST)
{
int i=0,W=0,A;
char ch;
char toAen;
for(i=0;i<CG;i<<)
ostfiISiT=U U;
ush1(URU);
i=0;
CP LAB MANUAL 53
toAen=infiISiT;
Dhile(toAenE=U30U)
{
if(isalnum(toAen))
{
ostfiISWT=toAen;
W<<;
=
else if(toAen==U(U)
{
ush1(U(U);
=
else if(toAen==U)U)
{
Dhile(stacA1Sto1TE=U(U)
{
ch=o1();
ostfiISWT=ch;
W<<;
=
ch=o1();
=
else
{
Dhile(*1"rioritQ(stacA1Sto1T)>=*0"(toAen))
{
ch=o1();
ostfiISWT=ch;
W<<;
=
ush1(toAen);
=
i<<;
toAen=infiISiT;
=
Dhile(to1E=0)
{
ch=o1();
ostfiISWT=ch;
W<<;
=
ostfiISWT=U30U;
=
/*<e'e)*inin- '(e .)io)i', o# e$e*en'! '(a' a)e .$ace" in!i"e '(e !'ac?. */
int *1"rioritQ(char toAen)
{
sDitch(toAen)
{
case U(U5return (0);
case U)U5return (G);
case U<U5return (C);
case U8U5return (C);
case UOU5return (F);
case U9U5return (F);
case URU5return (0);
default5 rintf(!*nvalid eIression!);
=
return 0;
=
/*<e'e)*inin- '(e .)io)i', o# e$e*en'! '(a' a)e a..)oac(in- 'o%a)"! '(e
!'ac?. */
int *0"(char toAen)
{
sDitch(toAen)
{
case U(U5return (10);
case U)U5return (G);
case U<U5return (C);
case U8U5return (C);
case UOU5return (F);
case U9U5return (F);
case U30U5return (0);
default5 rintf(!*nvalid eIression!); = return 0; =
CP LAB MANUAL 54
/*Ca$c$a'in- '(e )e!$' o# e4.)e!!ion/ %(ic( i! con0e)'e" in .o!'#i4
no'a'ion. */
float eval(char ST, float I1)
{
float t1,t2,A,r;
int i=0,l;
l=strlen();
Dhile(i<l)
{
if(SiT==UIU)
ush(I1);
else
if(isdi>it(SiT))
{
A=SiT8U0U;
ush(A);
=
else
{
t1=o();
t2=o();
sDitch(SiT)
{
case U<U5A=t2<t1;
breaA;
case U8U5A=t28t1;
breaA;
case UOU5A=t2Ot1;
breaA;
case U9U5A=t29t1;
breaA;
default5 rintf(!3n3t*nvalid eIression!);
=
ush(A);
=
i<<;
=
if(to>0)
{
rintf(!Vou have entered the oerands more than the oerators!);
eIit(0);
=
else
{
r=o();
return (r);
=
return 0;
=
O'.'&
.nter an eIression5 2
.nter I0, In and number of sub8intervals5
2.@
@.M
@
(he value of inte>ral is 1.MNC
/*17 b) W)i'e C .)o-)a* 'o i*.$e*en' ;)a.eJoi"a$ *e'(o".*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
char ostfiISF0T;
float stacASF0T;
char stacA1SF0T;
int to=81,to1=81;
float eval(char ostfiIST, float I1);
void infiIHostfiI(char infiIST);
main()
{
float I0, In, h, s,e1,e2;
char eISF0T, arrSF0T;
int i,n,l=0;
clrscr();
rintf(!3n.nter an eIression5 !);
>ets(eI);
CP LAB MANUAL 55
uts(!.nter I0, In and number of subintervals!);
scanf(!6f6f6d!, 7I0, 7In, 7n);
h=(In8I0)9n;
if(eIS0T==UlU77 eIS1T==UoU77 eIS2T==U>U)
{
l=strlen(eI);
for(i=0;i<l8@; i<<)
arrS0T=eISi<@T;
arrSiT=U30U;
infiIHostfiI(arr);
e1=eval(ostfiI,I0);
e2=eval(ostfiI,In);
s=lo>(e1)<lo>(e2);
for (i=1;i<=n81;i<<)
s<=2Olo>(eval(ostfiI,I0<iOh));
=
else
{
infiIHostfiI(eI);
s=eval(ostfiI,I0)<eval(ostfiI,In);
for (i=1;i<=n81;i<<)
s<=2Oeval(ostfiI,I0<iOh);
=
rintf(!;alue of the inte>ral is 6N.@f3n!,(h92)Os);
return(0);
=
9O*nsertin> the oerands in a stacA. O9
void ush(float item)
{
if(to==GG)
{
rintf(!3n3t(he stacA is full!);
>etch();
eIit(0);
=
else
{
to<<;
stacAStoT=item;
=
return;
=
9O#emovin> the oerands from a stacA. O9
float o()
{
float item;
if(to==81)
{
rintf(!3n3t(he stacA is emtQ3n3t!);
>etch();
=
item=stacAStoT;
to88;
return (item);
=
void ush1(char item)
{
if(to1==CG)
{
rintf(!3n3t(he stacA is full!);
>etch();
eIit(0);
=
else
{
to1<<;
stacA1Sto1T=item; =
return;
=
9O#emovin> the oerands from a stacA. O9
char o1()
{
char item;
if(to1==81) {
CP LAB MANUAL 56
rintf(!3n3t(he stacA1 is emtQ3n3t!);
>etch();
=
item=stacA1Sto1T;
to188;
return (item);
=
/*Con0e)'in- an in#i4 e4.)e!!ion 'o a .o!'#i4 e4.)e!!ion. */
void infiIHostfiI(char infiIST)
{
int i=0,W=0,A;
char ch;
char toAen;
for(i=0;i<CG;i<<)
ostfiISiT=U U;
ush1(URU);
i=0;
toAen=infiISiT;
Dhile(toAenE=U30U)
{
if(isalnum(toAen))
{
ostfiISWT=toAen;
W<<;
=
else if(toAen==U(U)
{
ush1(U(U);
=
else if(toAen==U)U)
{
Dhile(stacA1Sto1TE=U(U)
{
ch=o1();
ostfiISWT=ch;
W<<;
=
ch=o1();
=
else
{
Dhile(*1"rioritQ(stacA1Sto1T)>=*0"(toAen))
{
ch=o1();
/*A!!i-nin- '(e .o..e" e$e*en' in'o '(e .o!'#i4 a))a,. */
ostfiISWT=ch;
W<<;
=
ush1(toAen);
=
i<<;
toAen=infiISiT;
=
Dhile(to1E=0)
{
ch=o1();
ostfiISWT=ch;
W<<;
=
ostfiISWT=U30U;
=
*nt *1"rioritQ(char toAen)
{
sDitch(toAen)
{
case U(U5return (0);
case U)U5return (G);
case U<U5return (C);
case U8U5return (C);
case UOU5return (F);
case U9U5return (F);
case URU5return (0);
default5 rintf(!*nvalid eIression!);
breaA; =
CP LAB MANUAL 57
return 0;
=
/*<e'e)*inin- '(e .)io)i', o# e$e*en'! '(a' a)e a..)oac(in- 'o%a)"! '(e
!'ac?. */
int *0"(char toAen)
{
sDitch(toAen)
{
case U(U5return (10);
case U)U5return (G);
case U<U5return (C);
case U8U5return (C);
case UOU5return (F);
case U9U5return (F);
case U30U5return (0);
default5 rintf(!*nvalid eIression!);
breaA;
=
return 0;
=
/*Ca$c$a'in- '(e )e!$' o# e4.)e!!ion/ %(ic( i! con0e)'e" in .o!'#i4
no'a'ion. */
float eval(char ST, float I1)
{
float t1,t2,A,r;
int i=0,l;
l=strlen();
Dhile(i<l)
{
if(SiT==UIU)
ush(I1);
else
if(isdi>it(SiT))
{
A=SiT8U0U;
ush(A);
=
else
{
t1=o();
t2=o();
sDitch(SiT)
{
case U<U5A=t2<t1;
breaA;
case U8U5A=t28t1;
breaA;
case UOU5A=t2Ot1;
breaA;
case U9U5A=t29t1;
breaA;
default5 rintf(!3n3t*nvalid eIression!);
breaA;
=
ush(A);
=
i<<;
=
if(to>0)
{
rintf(!Vou have entered the oerands more than the oerators!);
eIit(0);
=
else
{
r=o();
return (r);
=
return 0;
=
O'.'5
.nter an eIression5 G
.nter I0, In and number of subintervals
5.3 3.7 9 Value of the integral is -14.400
CP LAB MANUAL 58

Das könnte Ihnen auch gefallen