Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views60 pages

C Lab Manual

2nd Sem C Program Manual for CSE

Uploaded by

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

C Lab Manual

2nd Sem C Program Manual for CSE

Uploaded by

collegevins4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Ex No 1.

PROGRAMS USING I/O STATEMENTS AND EXPRESSIONS


A) ADDITION OF TWO NUMBERS

AIM:
T o w rite a c p ro g ra m to p ro d u c e th e a d d itio n o f g iv en tw o N u m b ers .

ALGORITHM:
S tep 1 : D ec la re th e n e c es s a ry va ria b les a , b a n d c a s in teg er.
S tep 2 : R ea d th e in p u t o f th e in te g e r a a n d b .
S tep 3 : A d d a & b a nd s to re th e re s u lt in c
S tep 3 : D is p la y th e v a lu e o f c

PROGRAM:
# in c lu d e< s td io .h >
m a in ()
{
in t a ,b ,c ;
p rin tf("E n ter N u m b e r 1 \n ");
s c a n f ("% d ",& a );
p rin tf("E n ter N u m b e r 2 \n ");
s c a n f ("% d ",& b ) ;
c=a + b;
p rin tf("\n T h e A d d itio n R e s u lt is % d \ n ",c );
}

OUTPUT:

E n te r N u m b er 1
34
E n te r N u m b er 2
7
T h e A d d itio n R e s u lt is 4 1
RESULT:
T h u s th e c p ro g ra m to p ro d u c e th e a d d itio n re s u lt o f g ive n tw o n u m b e rs w a s
w ritten , e n te re d , e xe c u ted a n d th e o u tp u t w a s v erif ie d .

B) AVERAGE OF FIVE MARKS


AIM:
T o w rite a c p ro g ra m to c a lc u late th e A ve ra g e o f g ive n fiv e N u m b ers .

ALGORITHM:
S tep 1 : D ec la re fiv e in te g e r v a ria b le s to g et th e m a rk s .
S tep 2 : R ea d th e in p u t o f fiv e m a rk s a n d s to re th em in to in te g e r v a ria b le s .
S tep 3 : C a lc u late th e s u m o f five n u m b ers .
S tep 4 : D iv id e th e s u m b y 5 .
S tep 5 : D is p la y th e A ve ra g e

PROGRAM:
# in c lu d e< s td io .h >
m a in ()
{
in t m 1 ,m 2 ,m 3 ,m 4 ,m 5 ,to t;
flo a t a vg ;
p rin tf("E n ter 5 M a rk s \ n ");
s c a n f ("% d % d % d % d % d ",& m 1 ,& m 2 ,& m 3 ,& m 4 ,& m 5 );
to t= m 1 + m 2 + m 3 + m 4 + m 5 ;
a vg = to t/5 ;
p rin tf("\n T h e A ve ra g e is % f\n ",a v g );
}

OUTPUT:
E n te r N u m b er 5 m a rk s
34 55 6 7 88 99

T h e a v era g e is 6 8
RESULT:
T h u s th e c p ro g ra m to c a lc u la te th e A v era g e o f g iv en f iv e N u m b e rs w a s w ritte n ,
en te re d , e xe c u ted a nd th e o u tp u t w a s ve rif ie d

C)CALCULATOR
AIM:
To D es ig n a c a lc u la to r to p erfo rm th e o p e ra tio n , n a m e ly, a d d itio n ,
s u b tra c tio n ,m u ltip lic a tio n , d ivis io n a n d s q u a re o f a n u m b e r.

ALGORITHM:
S tep 1 .S ta rt th e p ro g ra m .
S tep 2 .R e a d a , b ,c .
S tep 3 .p rin t m en u
S tep 4 .rea d c h o ic e
S tep 5 .s w itc h (c h ):
5.1 Ad d
5 . 1 .1 R es u t-> a + b
5 . 1 .2 p rin t res u lt
5 . 2 s u b ra c t
5 . 2 .1 R es u t-> a -b
5 . 2 .2 p rin t res u lt
5 . 3 m ultip ly
5 . 3 .1 re s u t-> a *b
5 . 3 .2 p rin t res u lt
5 . 4 d iv id e
5 . 4 .1 re s u lt-> a /b
5 . 4 .2 p rin t res u lt
5 . 5 s q u a re
5 . 5 .1 re s u lt-> a *a
5 . 5 .2 re s u lt1 -> b *b
5 . 5 .3 p rin t res u lt
S tep 6 .s to p
PROGRAM:
# in c lu d e< s td io .h >
# in c lu d e< c o n io . h >
v o id m a in ()
{
in t a ,b ,res u lt,s q 1 ,s q 2 ,c h ;
flo a t d ivid e;
c lrs c r();
p rin tf("E n ter tw o in teg e rs :");
s c a n f ("% d % d ",& a ,& b );
p rin tf("1 .a d d ,2 .s u b tra c t,3 .m u ltip ly,4 .d iv id e,5 .s q u a re ");
p rin tf("\n E n ter the c h o ic e;");
s c a n f ("% d ",& c h ) ;
s w itc h (c h )
{
ca se 1:
{
res u lt= a+ b ;
p rin tf("Su m = % d \n ",res u lt);
b re a k ;
}
ca se 2:
{
res u lt= a-b ;
p rin tf("D iffere n c e =% d \ n ",re s u lt);
b re a k ;
}
ca se 3:
{
res u lt= a* b ;
p rin tf("M u ltip lic a tio n = % d \ n ",re s u lt) ;
b re a k ;
}
ca se 4:
{
res u lt= a/ (flo a t)b ;
p rin tf("D ivis io n = % . 2 f\ n ",re s u lt);
b re a k ;
}
ca se 5:
{
s q 1 = a *a ;
p rin tf("Sq u a re = % d \n ",s q 1 );
s q 2 = b *b ;
p rin tf("Se c o n d s q u a re =% d \ n ",s q 2 );
b re a k ;
}

}
g e tc h ();
}

RESULT:
T h u s th e p ro g ra m to D es ig n a c a lc u la to r to p e rfo rm th e o p era tio n , n a m e ly, a d d itio n ,
s u b tra c tio n , m u ltip lic a tio n , d iv is io n a n d s q u a re o f a n u m b e r w a s e xe c u ted a n d th e
o u tp ut w a s v erified .
.
Ex No.2 PROGRAMS USING DECISION-MAKING CONSTRUCTS
A)ODD OR EVEN
AIM:
T o w rite a c p ro g ra m to c h ec k w h eth e r g iv en N u m b er is o d d o r e ve n .

ALGORITHM:
S tep 1 : D ec la re a va ria b le to g et a N u m b e r
S tep 2 : R ea d th e in p u t
S tep 3 : G et th e re m a in d e r o f g ive n n u m b e r u s in g m o d u lo o p era to r
S tep 4 : If re m a in d e r is 0 p rin ts “ E ve n N u m b e r” , e ls e p rin t “ O d d N u m b e r” .

PROGRAM:
# in c lu d e< s td io .h >
m a in ()
{
in t a ,re m ;
p rin tf("E n ter a N u m b e r\ n ") ;
s c a n f ("% d ",& a );
rem = a % 2 ;
if(rem = = 0 )
p rin tf("Th e G ive n N u m b e r is E v en ");
els e
p rin tf("Th e G ive n N u m b e r is O d d ");
}

OUTPUT:
E n te r a N um b er
13
T h e G iv en N u m b er is O d d

RESULT:
T h u s th e c p ro g ram to c h ec k w h eth er g iv en N u m b e r is o d d o r e ve n w a s w ritte n ,
en te re d , e xe c u ted a nd th e o u tp u t w a s ve rif ie d .

B)BIGGEST OF 3 NUMBERS
AIM:
T o w rite a c p ro g ra m to e xa m in e th e b ig g es t o f g iv en thre e n u m b ers .

ALGORITHM:
S tep 1 : D ec la re th ree in teg er v a ria b les
S tep 2 : R ea d th e 3 in p uts
S tep 3 : C o m p a re firs t tw o n u m b ers a n d g o to S tep 4
S tep 4 : If firs t n u m b e r is g re a ter th a n s e c o n d n u m b er th en c o m p a re firs t n u m b er
w ith th ird n u m b e r e ls e g o to s tep 6
S tep 5 : If firs t n u m b e r is g rea ter th a n third nu m b er p rin t firs t n u m b e r a s b ig g es t
n u m b er els e p rin t th ird n u m b er a s b ig g es t
S tep 6 : C o m p a re s ec o n d n um b er w ith th ird n u m b er
S tep 7 : If s ec o n d n u m b e r is g rea ter th a n th ird n u m b er p rin t s e c o n d n u m b e r as
b ig g e s t n u m b er els e p rin t th ird n u m b er a s b ig g es t

PROGRAM:
# in c lu d e< s td io .h >
m a in ()
{
in t a ,b ,c ;
p rin tf("E n ter 3 N um b ers \n ");
s c a n f ("% d % d % d ",& a ,& b ,& c );
if(a > b )
{
I f(a > c )
{
p rin tf( "T h e F irs t N u m b e r % d (a ) is B ig g es t\ n ",a );
}
}
els e if( b > c )
{
p rin tf("Th e S ec o n d N u m b er % d (b ) is B ig g e s t\ n ",b );
}
els e
p rin tf("Th e T h ird N u m b er % d (c ) is B ig g e s t\ n ",c ) ;
}
OUTPUT:
E n te r 3 N u m b e rs
5
9
2
T h e S e c o n d N u m b e r 9 (b ) is B ig g e s t

RESULT:
T h u s th e c p ro g ram to e xa m in e th e b ig g es t o f g ive n th re e n u m b e rs w a s w ritte n ,
en te re d , e xe c u ted a nd th e o u tp u t w a s ve rif ie d .
C)LEAP YEAR OR NOT
AIM:
T o W rite a p ro g ra m to fin d w h e th e r th e g iv en yea r is le a p yea r o r no t.
ALGORITHM:
S tep 1 .S ta rt th e p ro g ra m .
S tep 2 .R e a d Y e a r.
S tep 3 .IF Y e a r% 4 = 0 .
S tep -3 .1 IF Y e a r% 1 0 0 = 0 .
S tep -3 .1 .1 IF Y e a r% 4 0 0 = 0 .
S tep -3 .1 .2 P rin t “ Le a p Y e a r” .
S tep -3 .1 .3 E L S E P rin t “ N o t L ea p Y ea r.
S tep -3 .2 E L S E P rin t “ Le a p Y e a r” .
S tep 4 .P rin t “ N o t L ea p Y ea r” .
S tep 5 . S to p .
PROGRAM:
# in c lu d e < s td io . h >
# in c lu d e< c o n io . h >
v o id m a in ()
{
in t ye a r;
c lrs c r();
p rin tf("E n ter a ye a r: ");
s c an f ("% d ",& ye a r);
if(ye a r% 4 = = 0 )
{
if( yea r% 1 0 0 = = 0 )
{
if ( yea r% 4 0 0 = = 0 )
p rin tf("% d is a le a p yea r.", yea r);
e ls e
p rin tf("% d is n o t a lea p yea r.", yea r);
}
e ls e
p rin tf("% d is a le a p yea r.", yea r );
}
e ls e
p rin tf("% d is n o t a lea p yea r.", yea r);
g e tc h ();
}
RESULT:
T h u s th e p ro g ra m to fin d w h e the r th e g ive n ye a r is lea p yea r o r n o t w a s e xe c u te d
a n d th e o u tp ut w a s v erified .
EX NO:3 LOOPS: FOR, WHILE, DO-WHILE
A)SUM OF ‘ N’ NATURAL NUMBERS
AIM:
T o w rite a c p ro g ra m to fin d th e s u m o f “ N ‟ n a tu ra l n u m b e rs fo r g iv en ra n g e.

ALGORITHM:
S tep 1 : In itia liz e th e s u m a s 0
S tep 2 : R ea d th e ra n g e a s in p u t
S tep 3 : In itia liz e a c o un te r w ith 1
S tep 4 : O ve rw rite th e s u m b y a d d in g c o un te r v a lu e & s u m
S tep 5 : In c rem en t th e c o u n ter va lu e b y 1
S tep 6 : R ep ea t th e s tep s 4 & 5 u n til th e c o u n ter is le s s th a n o r eq u al to ra ng e
S tep 7 : P rin t th e s u m

PROGRAM:
# in c lu d e< s td io .h >
m a in ()
{
in t i,n ,s um = 0 ;
p rin tf("E n ter th e ra n g e \ n");
s c a n f ("% d ",& n );
i= 1 ;
w h ile (i< = n )
{
s u m = s u m + i;
i+ + ;
}
p rin tf("\n T h e s u m o f firs t % d n u m b e rs is % d \n ",n ,s u m );
}
OUTPUT:
E n te r th e ra ng e
16
T h e s u m o f firs t 1 6 nu m b ers is 1 3 6

RESULT:
T h u s th e c p ro g ra m to f in d th e s u m o f „ N ‟ n a tu ra l n u m b e rs fo r g ive n ra n g e
w a s w ritte n, en tered , ex ec u te d a n d th e o u tp u t w a s ve rified .

B)CHECK WHETHER A GIVEN NUMBER IS ARMSTRONG NUMBER OR NOT?


AIM:
T o w rite a C P ro g ra m to C h e c k w h e th e r a g iv en n u m b er is A rm s tro n g n u m b e r o r
not .
ALGORITHM:
S tep 1 . S ta rt

S tep 2 . D e c la re va ria b les

S tep 3 . R e a d th e In p u t n u m b er.

S tep 4 . C a lc u la te s u m o f c u b ic o f in d ivid u a l d ig its o f th e in p u t.

S tep 5 . M a tc h th e res u lt w ith in p u t n u m b er.

S tep 6 . If m atc h , D is p la y th e g ive n n um b er is A rm s tro n g o th erw is e n o t.

S tep 7 . S to p
PROGRAM:
# in c lu d e< s td io .h >
# in c lu d e< c o n io . h >
# in c lu d e< m a th. h >
v o id m a in ()
{
in t n u m b e r, s u m = 0 , rem = 0 , c u b e = 0 , tem p ;
c lrs c r();
p rin tf ( "e n te r a n u m b e r");
s c a n f ("% d ", & n u m b er);
tem p = n u m b er;
w h ile ( n u m b er != 0 )
{
rem = n u m b e r % 1 0 ;
c u b e = p o w ( re m , 3 );
s u m = s u m + c u b e;
n u m b er = n u m b er / 1 0 ;
}
if (s u m = = tem p )
p rin tf ( "T h e g ive n n o is a rm s tro n g n o ");
els e
p rin tf ( "T h e g ive n n o is n o t a a rm s tro n g n o ");
g e tc h ();
}

RESULT:
T h u s a C P ro g ra m fo r A rm s tro n g n u m b er c h ec k in g w a s ex ec u ted a n d th e o u tp u t
w a s o b ta in ed .

D)POPULATE AN ARRAY WITH HEIGHT OF PERSONS AND FIND HOW MANY PERSONS
ARE ABOVE THE AVERAGE HEIGHT.
AIM:
T o w rite a C P ro g ra m to p o p u la te a n a rra y w ith h eig h t o f p e rs o n s a n d f in d h o w
m a n y p ers o n s a re a b o ve th e a v era g e h eig h t.

ALGORITHM:

S tep 1 → T a k e a n a rra y A a n d d efin e its va lu es

S tep 2 → L o o p fo r ea c h v a lu e o f A

S te p 3 → A d d ea c h elem en t to 's u m ' va ria b le

S tep 4 → A fte r lo o p fin is h es , d ivid e s um w ith n u m b er o f a rra y e le m en ts

S te p 5 → S to re th a t res u lt to a v g va ria b le a n d d is p la y.
PROGRAM:
# in c lu d e< s td io .h >
# in c lu d e< c o n io . h >
v o id m a in ()
{
flo a t a r[1 0 0 ];
in t n ,i,s u m = 0 ,c o u nt= 0 ;
flo a t a vg ;
flo a t a vg h t= 5 . 1 ;

p rin tf( "E n te r th e n u m b e r o f p ers o ns \ n ") ;


s c a n f( "% d ",& n );

p rin tf( "E n te r th e h e ig h t\ n ");


fo r(i= 0 ;i< n ;i+ + )
{
s c a n f("% d ",& a r[i]);

}
fo r(i= 0 ;i< n ;i+ + )

{
if(a r[i]> =a v g h t)
c o u n t=c o u n t+ 1 ;
}

p rin tf( " n o o f p e rs o n s a b o v e a vg h t is % d ",c o u n t);


g e tc h ();
}
RESULT:
T h u s th e C Pro g ra m to p o p u late a n a rra y w ith h e ig h t o f p ers o n s a n d fin d h o w m a n y
p e rs o n s a re a b o v e th e a v era g e h e ig h t w a s ex ec u ted a n d th e o u tp u t w a s ve rified .

EX NO:4 ARRAYS: 1D AND 2D, MULTI-DIMENSIONAL ARRAYS, TRAVERSAL

AIM:
T o w rite a C P ro g ra m to p o p u la te a n a rra y w ith h eig h t o f p e rs o n s a n d f in d h o w
m a n y p ers o n s a re a b o ve th e a v era g e h eig h t.
ALGORITHM:
S tep 1 . S ta rt
S tep 2 . D e c la re va ria b les
S tep 3 . R e a d th e to ta l n u m b er o f p ers o n s a n d th eir h e ig h t.
S tep 4 . C a lc u la te a vg = s u m / n a n d fin d n u m b er o f p ers o n s th eir h > a vg .
S tep 5 . D is p la y th e o u tp u t o f th e c a lc ula tio n s .
S tep 6 . S to p

PROGRAM:
/ * G et a H e ig h t o f D iffe re n t P ers o n s a n d f in d ho w m a n y o f th em a re a re a b o v e a v era g e */
# in c lu d e < s td io . h >
# in c lu d e < c o n io .h >
v o id m a in ()
{
in t i,n ,s um = 0 ,c o u n t= 0 ,h e ig h t[1 0 0 ];
flo a t a vg ;
c lrs c r();
p rin tf("E n ter th e N u m b e r o f Pe rs o n s : ");
s c a n f ("% d ",& n );
p rin tf("\n E n ter the H eig h t o f ea c h p e rs o n in c e n tim eter\ n ") ;
fo r(i= 0 ;i< n ;i+ + )
{
s c a n f ("% d ",& h eig h t[i]);
s u m = s u m + h eig h t[i];
}
a vg = ( flo a t)s u m / n ;
/ /C o u n tin g
fo r(i= 0 ;i< n ;i+ + )
if(h e ig h t[i]> a v g )
c o u n t+ + ;
p rin tf("\n A v era g e H e ig h t o f % d p ers o n s is : % . 2 f\ n ",n ,a vg );
p rin tf("\n T h e n u m b er o f p ers o n s a b o ve a ve ra g e : % d ",c o u n t) ;
g e tc h ();
}
RESULT:
T h u s a C P ro g ra m a ve ra g e h e ig h t o f p ers o n s w a s e xe c u ted a n d th e o u tp u t w a s
o b ta in e d .

Ex No :5 COMPUTE BODY MASS INDEX


AIM:
T o w rite a C P ro g ra m to P o p u la te a tw o d im en s io n a l a rra y w ith h eig h t a n d w eig h t
o f p ers o n s a n d c o m p u te th e B o d y M a s s In d ex o f th e in d iv id u a ls .
ALGORITHM:
1 . S ta rt
2 . D ec lare v a ria b le s
3 . R ea d th e n u m b e r o f p e rs o n s a n d th e ir h eig h t a n d w eig h t.
4 . C a lc u la te B M I= W / H 2 fo r e a c h p e rs o n
5 . D is p la y th e o u tp u t o f th e B M I fo r e a c h p e rs o n .
6 . S to p
PROGRAM:
# in c lu d e < s td io . h >
# in c lu d e < c o n io .h >
v o id m a in ()
{
in t s tu [1 0 0 ][2 ];`
in t in d ex [1 0 0 ];
in t i,n ;
flo a t h ;
c lrs c r();
p rin tf("E n te r th e n u m b er o f s tu d e n ts : ") ;
s c a n f("% d ",& n) ;
fo r(i= 0 ;i< n ;i+ + )
{
p rin tf( "E n te r th e H eig h t(c m ) an d W eig h t(k g ) o f s tu d e nt % d :",i+ 1 );
s c a n f( "% d % d ",& s tu [i][0 ],& s tu [i][1 ]);
h = (f lo a t) (s tu [i][0 ]/1 0 0 . 0 );
in d ex [i] = (flo a t)s tu [i][1 ]/( flo a t)(h *h );
}
p rin tf("\ n S tu .N o .\tH eig h t\ tW eig h t\ tB M I\ tR es u lt\n ");
fo r(i= 0 ;i< n ;i+ + )
{
p rin tf("\n % d \t% d \t% d \t% d \t",i+ 1 ,s tu [i][0 ],s tu [i][1 ],in d e x[i]);
if(in d e x[i]< 1 5 )
p rin tf("S ta rv a tio n \n ");
e ls e if( in d ex [i]> 1 4 & & in d ex [i] < 1 8 )
p rin tf("U n d erw eig h t\ n ");
e ls e if( in d ex [i] > 1 7 & & in d e x[i] < 2 6 )
p rin tf("H ea lth y\n ");
e ls e if( in d ex [i] > 2 5 & & in d e x[i] < 3 1 )
p rin tf("O v er w eig h t\ n");
e ls e if( in d ex [i] > 3 0 & & in d e x[i] < 3 6 )
p rin tf("O b es e \n ");
e ls e
p rin tf("S ev ere O b e s e\ n ") ;
} / / fo r lo o p
g etc h ();
}
RESULT:
T h u s a C P ro g ram B o d y M a s s In d e x o f th e in d iv id u a ls w a s e xe c u ted a n d th e
o u tp ut w a s o b ta in ed .

EX NO:6 STRINGS: OPERATIONS

AIM
T o w rite a C P ro g ra m to p erfo rm s trin g o p era tio n s o n a g ive n p a ra g ra p h fo r th e
fo llo w in g u s in g b u ilt-in f u n c tio n s :
a . F in d the to tal n u m b er o f w o rd s .
b . C a p ita liz e th e firs t w o rd o f e a c h s en ten c e.
c . R ep la c e a g iv en w o rd w ith a n o th er w o rd .

ALGORITHM
S te p 1 . S ta rt
S te p 2 . D e c la re v a ria b le s
S te p 3 . R e a d th e tex t.
S te p 4 . D is p la y th e m en u o p tio n s
S te p 5 . C o m p a re e a c h c h a ra c ter w ith ta b c h a r ‘ \ t’ o r spac e c har ‘ ‘ to c o u n t
n o o f w o rd s
S te p 6 . F in d th e firs t w o rd o f e ac h s en ten c e to c a p ita lize b y c h ec k s to s e e if a
c h a ra c te r is a p u n c tu a tio n m a rk u s e d to d e n o te th e e n d o f a s en ten c e. (! . ? )
S te p 7 . R e p la c e the w o rd in th e tex t b y us e r s p ec ific w o rd if m a tc h .
S te p 8 . D is p la y th e o u tp u t o f th e c a lc u la tio n s .
S te p 9 . R e p e a t th e s tep 4 till c h o o s e th e o p tio n s to p .
S te p 1 0 .S to p

PROGRAM
# in c lu d e < s td io . h >
# in c lu d e < s td lib .h >
# in c lu d e < s trin g .h >
v o id rep la c e (c h a r *, c h a r *, c h a r *);
in t m a in( )
{
c h a r c h o ic e.s tr[2 0 0 ];
int i, w o rd s ;
c h a r s _s tring [2 0 0 ], r_ s trin g [2 0 0 ];
/* In p u t tex t f ro m u s er */
p rin tf( "E n te r a n y tex t:\ n ");
g e ts ( s tr);

do
{
p rin tf( "\ n 1 . F in d th e to ta l n u m b e r o f w o rd s \n ");
p rin tf( "2 . C a p ita liz e th e firs t w o rd o f ea c h s e n te n c e \ n ");
p rin tf( "3 . R e p la c e a g iv en w o rd w ith a n o th e r w o rd \ n ") ;
p rin tf( "4 . S to p \ n ") ;
p rin tf( "E n te r yo u r c h o ic e : ");
c h o ic e= g etc h a r();
s w itc h ( c h o ic e)
{
c a s e '1 ' :
i = 0;
w o rd s = 1 ;
/* R u n s a lo o p till en d o f te xt */
w hile( s tr[i] != '\ 0 ')
{
/* If th e c u rre nt c h a ra c te r(s tr[i]) is w h ite s p a c e */
if(s tr[i]= = ' ' || s tr[i]= = '\ n ' || s tr[i]= = '\ t')
{
w o rd s + + ;
}
i+ + ;
}
p rin tf( "\ n T o ta l n u m b e r o f w o rd s = % d ", w o rd s );
b re a k ;
c a s e '2 ' :
i = 0;
/* R u n s a lo o p till en d o f te xt */
w hile( s tr[i] != '\ 0 ')
{
/* C h ec k s to s e e if a c h a ra c te r is a p u n c tu a tio n m a rk u s ed to d en o te
th e en d o f a s en ten c e. (! . ? ) */
if(s tr[i]= = '!' || s tr[i]= = '.' || s tr[i]= = '? ')
{
i+ + ;
w h ile (s tr[i]!= ' ' || s tr[i]!= '\n ' || s tr[i]!= '\ t || s tr[i] != '\ 0 '’ )
{p u tc h a r ( to u p p e r(s tr[+ + i])) ;
i+ + ;
}
}
els e
p u tc h ar (s tr[i]);
i+ + ;
}
b re a k ;
c a s e '3 ' :
/ *G et th e s ea rc h a n d rep la c e s trin g fro m th e u s e r.
· W rite a us e r d efin e d fu n c tio n to rep la c e th e firs t o c c u rren c e o f th e s ea rc h s trin g w ith th e
rep la c e s trin g .
· R ec u rs iv ely c a ll th e fu n c tio n u n til th ere is n o o c c u rren c e o f th e s e a rc h s trin g .*/
p rin tf("\n P lea s e e n ter th e s trin g to s e a rc h : ");
fflu s h (s td in );
g e ts ( s _s trin g );
p rin tf( "\ n P le a s e e n te r th e rep la c e s trin g ");
fflu s h (s td in );
g e ts ( r_ s trin g );
re p la c e(s tr, s _s trin g , r_ s trin g );
p u ts (s tr);
b re a k ;
c a s e '4 ' :
ex it(0 );
}
p rin tf("\n P res s a n y k ey to c o n tin u e. ...");
g e tc h ();
}
w h ile (c h o ic e!= ’ 4’ );
retu rn 0 ;
}
v o id rep la c e(c h a r * s tr, c h a r * s _ s trin g , c h a r * r_s trin g ) {
// a b u ffe r v a ria b le to d o a ll re p la c e th in g s
c h a r b u ffe r[2 0 0 ];
// to s to re th e p o in te r retu rn e d fro m s trs tr
cha r * c h;
// firs t ex it c o n d itio n
if(!(c h = s trs tr( s tr, s _ s trin g )))
re tu rn ;
// c o p y a ll th e c o n ten t to b u ffe r b efo re th e firs t o c c u rre n c e o f th e s ea rc h s trin g
s trn c p y(b u ffer, s tr, c h -s tr);
// p re p a re th e b u ffe r f o r a p p e n d in g b y a d d in g a n u ll to th e en d o f it
b u f fer[c h -s tr] = 0 ;
// a p p en d u s in g s p rin tf fu n c tio n
s p rin tf( b u ffe r+ (c h -s tr), "% s % s ", r_s trin g , c h + s trle n (s _ s trin g ));
// em p ty s tr fo r c o p yin g
s tr[0 ] = 0 ;
s trc p y(s tr, b u ffe r);
// p a s s rec u rs iv ely to re p la c e o th er o c c u rre n c e s
re tu rn rep la c e(s tr, s _s tring , r_s trin g );
}
OUTPUT
E n te r a n y te xt:
I lik e C a n d C + + p ro g ra m m in g !
1 . F in d th e to ta l n u m b e r o f w o rd s
2 . C a p ita liz e th e firs t w o rd o f e a c h s en ten c e
3 . R ep lac e a g iv en w o rd w ith a n o th er w o rd
4 . S to p
E n te r yo u r c h o ic e : 1
T o ta l nu m b er o f w o rd s = 6
P res s a n y k ey to c o n tin u e. ...
1 . F in d th e to ta l n u m b e r o f w o rd s
2 . C a p ita liz e th e firs t w o rd o f e a c h s en ten c e
3 . R ep lac e a g iv en w o rd w ith a n o th er w o rd
4 . S to p
E n te r yo u r c h o ic e : 4

RESULT
T h u s a C P ro g ra m S trin g o p era tio n s w a s e xe c u ted a n d th e o u tp u t w a s o b ta in e d .
EX NO:7 FUNCTIONS: CALL, RETURN, PASSING PARAMETERS BY (VALUE,
REFERENCE), PASSING ARRAYS TO FUNCTION
(A)LEAP YEAR OR NOT?

AIM:
T o w rite a c p ro g ra m to c h ec k w h eth e r th e g iv en yea r is le ap o r n o t u s in g fu n c tio n s .

ALGORITHM:
S tep 1 : C re a te a f un c tio n is le ap ()
S tep 2 : In s id e th e fu n c tio n a .
R e a d th e yea r a s in p u t b .
E x tra c t th e rem a in d er fro m d ivis io n o p era tio n o f yea r b y 4 c .
If rem a in d e r is 0 p rin t “ G iv en yea r is L ea p ye a r” e ls e p rin t
“ G iv en yea r is n o t a Le a p yea r”
S tep 3 : In s id e th e m a in fu n c tio n c a ll th e is le a p () fu n c tio n

PROGRAM:
# in c lu d e< s td io .h >
v o id is le a p ()
{
in t yr;
p rin tf("E n ter a Y ea r\n ");
s c a n f ("% d ",& yr);
if(yr% 4 == 0 )
p rin tf("G ive n Y ea r is L ea p ye a r");
els e
p rin tf("G ive n Y ea r is N o t a Lea p yea r") ;
}
m a in ()
{
is lea p ( );
}

OUTPUT:
E n te r a Y e a r
19 65
G iv en Y e a r is N o t a Le a p ye a r

RESULT:
T h u s th e c p ro g ra m to c h e c k w h eth er th e g ive n ye a r is lea p o r n o t u s in g
fu n c tio n s w a s w ritte n , en tered , ex ec u ted a n d th e o u tp u t w a s ve rifie d .

EX NO:8 SORTING USING PASS BY REFERENCE

AIM
T o w rite a C P ro g ra m to S o rt th e lis t o f n u m b e rs u s in g p a s s b y ref eren c e.

ALGORITHM
S te p 1 . S ta rt
S te p 2 . D e c la re v a ria b le s a n d c rea te a n a rra y
S te p 3 . R e a d th e In p u t fo r n u m b e r o f e lem en ts a n d ea c h e lem en t.
S te p 4 . D e ve lo p a fu n c tio n to s o rt th e arra y b y p a s s in g refe ren c e
S te p 5 . C o m p a re the elem e n ts in e a c h p as s till a ll th e e le m e n ts a re s o rted .
S te p 6 . D is p la y th e o u tp u t o f th e s o rted elem e nts .
S te p 7 . S to p

PROGRAM
# in c lu d e < s td io . h >
# in c lu d e < c o n io .h >
v o id m a in ()
{
int n ,a [1 0 0 ],i;
vo id s o rta rra y(in t*,int);
c lrs c r();
p rin tf( "\ n E n ter the N um b er o f E le m e n ts in an a rray : ") ;
s c a n f("% d ",& n );
p rin tf( "\ n E n ter the A rra y e le m en ts \n ");
fo r(i= 0 ;i< n ;i+ + )
s c a n f("% d ",& a [i]);
s o rta rra y(a ,n );
p rin tf( "\ n A fte r S o rtin g ... .\n ");
fo r(i= 0 ;i< n ;i+ + )
p rin tf( "% d \ n ",a [i]);
g e tc h ();
}
v o id s o rta rra y(in t* a rr,in t n u m )
{
in t i,j,tem p ;
fo r(i= 0 ;i< n u m ;i+ + )
fo r(j= i+ 1 ;j< n u m ;j+ + )
if(a rr[i] > a rr[j])
{
tem p = a rr[i];
a rr[i] = a rr[j];
a rr[j] = tem p ;
}
}

OUTPUT
E n te r th e N u m b er o f E le m e n ts in a n a rra y : 5
E n te r th e A rra y e lem en ts
33
67
21
45
11
A f te r S o rtin g ... .
11
21
33
45
67

RESULT
T h u s a C P ro g ra m S o rtin g u s in g p a s s b y refe re n c e w a s e xe c u ted a n d th e o u tp u t w a s
o b ta in e d .

EX NO: 9 RECURSION

TOWERS OF HANOI USING RECURSION


AIM

T o w rite a C P ro g ra m to S o lve to w e rs o f H a n o i u s in g rec u rs io n.

ALGORITHM

S te p 1 . S ta rt

S te p 2 . D e c la re v a ria b le s

S te p 3 . R e a d th e In p u t fo r n u m b e r o f d is c s .

S te p 4 . C h e c k th e c o n d itio n fo r ea c h tra n s fer o f d is c s us in g re c u rs io n .

S te p 5 . D is p la y th e o u tp u t o f th e e a c h m o ve .

S te p 6 . S to p

PROGRAM

# in c lu d e < s td io . h >
# in c lu d e < c o n io .h >
v o id to w ero f h an o i(in t n , c h a r fro m , c h a r to , c h a r a u x)
{
if (n = = 1 )
{
p rin tf("\n M o ve d is k 1 fro m p eg % c to p e g % c ", fro m , to );
retu rn ;
}
to w ero f h a n o i(n -1 , fro m , a u x, to );
p rin tf("\n M o ve d is k % d fro m p e g % c to p eg % c ", n , fro m , to );
to w ero f h a n o i(n -1 , a u x, to , fro m );
}
in t m a in( )
{
int n ;
c lrs c r();
p rin tf( "E n te r th e n u m b e r o f d is k s : ");
s c a n f("% d ",& n ); / / N u m b e r o f d is k s
to w ero fh a n o i( n , 'A ', 'C ', 'B ') ; / / A , B a n d C a re n a m es o f p eg
g e tc h ();
re tu rn 0 ;
}

OUTPUT

E n te r th e n u m b er o f d is k s : 3
M o v e d is k 1 fro m p e g A to p e g C
M o v e d is k 2 fro m p e g A to p e g B
M o v e d is k 1 fro m p e g C to p e g B
M o v e d is k 3 fro m p e g A to p e g C
M o v e d is k 1 fro m p e g B to p eg A
M o v e d is k 2 fro m p e g B to p eg C
M o v e d is k 1 fro m p e g A to p e g C
RESULT

T h u s a C P ro g ra m T o w e rs o f H a n o i u s in g R ec u rs io n w as ex ec u te d a n d th e o u tp u t
w a s o b ta in ed .

EX NO:10 SALARY SLIP OF EMPLOYEES

AIM
T o w rite a C P ro g ra m to G en e ra te s a la ry s lip o f e m p lo ye es u s in g s tru c tu res a n d
p o in te rs .

ALGORITHM
S te p 1 . S ta rt
S te p 2 . D e c la re v a ria b le s
S te p 3 . R e a d th e n u m b er o f e m p lo ye es .
S te p 4 . R e a d a llo w a n c e s , d e d u c tio n s a n d b a s ic fo r ea c h e m p lo ye e.
S te p 5 . C a lc u la te n e t p a y= (b a s ic + a llo w a n c e s )-d ed u c tio n s
S te p 6 . D is p la y th e o u tp u t o f th e P a y s lip c a lc u la tio n s fo r ea c h e m p lo yee .
S te p 7 . S to p

PROGRAM
# in c lu d e< s td io .h >
# in c lu d e< c o n io . h >
# in c lu d e "s td lib .h "
s tru c t e m p
{
int em p n o ;
c h a r n a m e [1 0 ], a n s w er ;
int b p a y, a llo w , d e d , n p a y ;
s tru c t em p *n e xt;
};
v o id m a in ()
{
int I,n = 0 ;
int m o re_ d a ta = 1 ;
s tru c t em p e *c u rre n t_p tr, *h e ad _p tr;
c lrs c r() ;
h ea d _p tr = ( s tru c t em p *) m a llo c (s ize o f( s tru c t em p ) );
c u rren t_p tr = he a d _ p tr;
w hile (m o re _d a ta )
{
{
p rin tf( "\ n E n ter the em p lo y ee n u m b e r : ") ;
s c a n f("% d ", & c u rre n t_ p tr-> e m p n o ) ;
p rin tf( "\ n E n ter the n a m e : ") ;
s c a n f ("% s ",& c u rre n t_ p tr-> n a m e) ;
p rin tf( "\ n E n ter the b a s ic p a y, a llo w a n c es & d e d u c tio n s : ") ;
s c a n f("% d % d % d ", & c u rre nt_ p tr -> b p a y, & c u rre n t_p tr -> a llo w , & c u rren t_p tr -
> d ed ) ;
e[i]. n p a y = e[i]. b p a y + e [i].a llo w - e[i].d e d ;
n++ ;
p rin tf("W o u ld yo u lik e to a d d a n o th e r e m p lo ye e? (y/ n ): ");
s c a n f("% s ", a n s w er);
if (a n s w er!= 'Y ')
{
c u rren t_p tr-> n ex t = (s tru c t e m e *) N U LL ;
m o re_ d a ta = 0 ;
}
els e
{
c u rren t_p tr-> n ex t = (s tru c t em p *) m a llo c (s ize o f(s tru c t em p ));
c u rren t_p tr = c u rren t_p tr-> n ex t;
}
}
}
p rin tf( "\ n E m p . N o . N a m e \ t B p a y \ t A llo w \ t D ed \ t N p a y \ n \ n") ;
c u rren t_p tr = he a d _ p tr;
fo r(i = 0 ; i < n ; i+ + )
{
p rin tf( "% d \t % s \t % d \ t % d \t % d \ t % d \ n", c u rre nt_ p tr-> e m p n o ,
c u rren t_p tr-> n a m e , c u rren t_p tr-> b p a y, c u rren t_p tr-> a llo w , c u rre n t_p tr-> d e d ,
c u rren t_p tr-> n p a y) ;
c u rren t_p tr= c u rre nt_ p tr-> n e xt;
}
g e tc h () ;
}

OUTPUT
E n te r th e n u m b er o f e m p lo yee s : 2
E n te r th e em p lo yee n u m b e r : 1 0 1
E n te r th e n a m e : A ru n
E n te r th e b a s ic p a y, a llo w a n c es & d e d u c tio n s : 5 0 0 0 1 0 0 0 2 5 0
E n te r th e em p lo yee n u m b e r : 1 0 2
E n te r th e n a m e : B a b u
E n te r th e b a s ic p a y, a llo w a n c es & d e d u c tio n s : 7 0 0 0 1 5 0 0 7 5 0
E m p .N o . N a m e B p a y A llo w D ed N p a y
1 0 1 A ru n 5 0 0 0 1 0 0 0 2 5 0 5 7 5 0
10 2 B abu 7 000 150 0 7 50 7 75 0

RESULT
T h u s a C P ro g ra m S a la ry s lip o f e m p lo ye es w a s ex ec u te d an d th e o u tp u t w a s
o b ta in e d .

EX NO:11 INTERNAL MARKS OF STUDENTS

AIM
T o w rite a C P ro g ra m to C o m p u te in tern a l m a rk s o f s tu d en ts fo r five d if feren t
s u b jec ts u s in g s tru c tu re s a n d f u n c tio n s .
ALGORITHM
S te p 1 . S ta rt
S te p 2 . D e c la re v a ria b le s
S te p 3 . R e a d th e n u m b er o f s tu d e n ts .
S te p 4 . R e a d th e s tu d e n t m a rk d e ta ils
S te p 5 . C a lc u la te in tern a l m a rk b y i= to ta l o f th ree tes t m a rk s / 3 fo r ea c h s u b je c t
per
s tu d e n t.
S te p 6 . D is p la y th e o u tp u t o f th e c a lc u la tio n s fo r a ll th e s tu d e n ts .
S te p 7 . S to p

PROGRAM
# in c lu d e< s td io .h >
# in c lu d e< c o n io .h >
s tru c t s tu d {
c h a r n a m e [2 0 ];
lo n g in t ro lln o ;
int m a rk s [5 ,3 ];
int i[5 ];

}s tu d en ts [1 0 ];
v o id c a lc in tern a l(in t) ;
int m a in () {
int a ,b ,j,n ;
c lrs c r();
p rin tf( "H o w m a n y s tu d e n ts : \n ");
s c a n f("% d ",& n );
fo r(a = 0 ;a < n ;+ + a ){
c lrs c r();
p rin tf( "\ n \n E n te r th e d eta ils o f % d s tu d e nt : ", a + 1 );
p rin tf( "\ n \n E n te r s tu d e n t % d N a m e : ", a );
s c a n f("% s ", s tu d e n ts [a ].n a m e);
p rin tf( "\ n \n E n te r s tu d e n t % d R o ll N u m b er : ", a );
s c a n f("% ld ", & s tu d e n ts [a ].ro lln o );
to ta l= 0 ;
fo r(b = 0 ;b < = 4 ;+ + b ){
fo r(j= 0 ;j< = 2 ;+ + j){
p rin tf( "\ n \n E n te r th e tes t % d m a rk o f s u b je c t-% d : ",j+ 1 , b + 1 );
s c a n f("% d ", & s tu d en ts [a ].m a rk s [b ,j]);
}
}
}
c a lc in te rn a l(n );
fo r(a = 0 ;a < n ;+ + a ){
c lrs c r();
p rin tf( "\ n \n \ t\t\ t\ tM a rk Sh e et\ n ");
p rin tf( "\ n N a m e o f S tu d en t : % s ", s tu d e n ts [a ].n a m e);
p rin tf( "\ t\t\t\ t R o ll N o : % ld ", s tu d e n ts [a ].ro lln o );
p rin tf( "\ n ------------------------------------------------------------------------");
fo r(b = 0 ;b < 5 ;b + + ){
p rin tf( "\ n \n \ t S u b je c t % d in te rn a l \ t\ t :\ t % d ", b + 1 , s tu d en ts [a ].i[b ]) ;
}
p rin tf( "\ n \n ------------------------------------------------------------------------\n ");
g e tc h ();
}
re tu rn (0 );
}
v o id c a lc in tern a l(in t n )
{
int a ,b ,j,to ta l;
fo r(a = 1 ;a < = n ;+ + a ){
fo r(b = 0 ;b < 5 ;b + + ){
to ta l=0 ;
fo r(j= 0 ;j< = 2 ;+ + j){
to ta l + = s tu d en ts [a ].m a rk s [b ,j];
}
s tu d en ts [a ]. i[b ]= to ta l/3 ;
}
}
}

OUTPUT
H o w m a n y s tu d e n ts : 1
E n te r th e d e ta ils o f 1 s tu d e n t :
E n te r s tu d e n t 1 N a m e : H .X e rio
E n te r s tu d e n t 1 R o ll N u m b e r : 5 3 6 4 3 5
E n te r th e tes t 1 m a rk o f s u b jec t-1 : 4 6
E n te r th e tes t 2 m a rk o f s u b jec t-1 : 5 6
E n te r th e tes t 3 m a rk o f s u b jec t-1 : 7 6
E n te r th e tes t 1 m a rk o f s u b jec t-2 : 8 5
E n te r th e tes t 2 m a rk o f s u b jec t-2 : 7 5
E n te r th e tes t 3 m a rk o f s u b jec t-2 : 7 5
E n te r th e tes t 1 m a rk o f s u b jec t-3 : 6 6
E n te r th e tes t 2 m a rk o f s u b jec t-3 : 8 6
E n te r th e tes t 3 m a rk o f s u b jec t-3 : 7 0
E n te r th e tes t 1 m a rk o f s u b jec t-4 : 2 5
E n te r th e tes t 2 m a rk o f s u b jec t-4 : 3 5
E n te r th e tes t 3 m a rk o f s u b jec t-4 : 6 1
E n te r th e tes t 1 m a rk o f s u b jec t-5 : 4 5
E n te r th e tes t 2 m a rk o f s u b jec t-5 : 7 5
E n te r th e tes t 3 m a rk o f s u b jec t-5 : 6 0
M a rk S h ee t
N a m e o f S tu d en t : H .X e rio R o ll N o : 5 3 6 4 3 5
------------------------------------------------------------------------
s u b je c t 1 in te rn a l : 5 9
s u b je c t 2 in te rn a l : 7 8
s u b je c t 3 in te rn a l : 7 4
s u b je c t 4 in te rn a l : 4 0
s u b je c t 5 in te rn a l : 6 0
------------------------------------------------------------------------

RESULT
T h u s a C P ro g ra m fo r In te rn a l m a rk s o f s tu d e n ts w a s ex ec u te d a n d th e o u tp u t w a s
o b ta in e d .
EX NO: 12 FILES: READING AND WRITING, FILE POINTERS, FILE OPERATIONS,
RANDOM ACCESS, PROCESSOR DIRECTIVES.

TELEPHONE DIRECTORY
AIM
T o w rite a C P ro g ra m to a d d , d ele te ,d is p la y ,S e a rc h a n d ex it o p tio n s fo r tele p h o n e
d e ta ils o f a n in d ivid ua l in to a tele p h o ne d irec to ry u s in g ra n d o m a c c es s file.

ALGORITHM
S te p 1 . S ta rt.
S te p 2 . D e c la re v a ria b le s , F ile p o in ter a n d p h o n eb o o k s tru c tu re s .
S te p 3 . C re a te m e n u o p tio n s .
S te p 4 . R e a d th e o p tio n .
S te p 5 . D e ve lo p p ro c e d u res fo r e a c h o p tio n .
S te p 6 . C a ll th e p ro c ed ure (A d d , d ele te ,d is p la y ,S ea rc h a n d ex it)fo r u s e r c h o s en
o p tio n .
S te p 7 . D is p la y th e m es s a g e fo r o p era tio n s p erfo rm ed .
S te p 8 . S to p

PROGRAM
# in c lu d e < s td io . h >
# in c lu d e < s td lib .h >
# in c lu d e < s trin g .h >
typ e d e f s tru c t P h o n eb o o k _C o n ta c ts
{
c h a r F irs tN a m e [2 0 ];
c h a r La s tN am e [2 0 ];
c h a r Ph o n eN u m b e r[2 0 ];
} p h o n e;
v o id A d d E n try(p h o n e * );
v o id D e leteE n try(p h o n e * );
v o id P rin tE n try(p h o n e * );
v o id S ea rc h F o rN u m b e r( p h o n e * );
in t c o u n ter = 0 ;
c h a r F ile N a m e [2 5 6 ];
F IL E *p R ea d ;
F IL E *p W rite;
in t m a in (v o id )
{
p h o n e *p h o n eb o o k ;
p h o n eb o o k = (p h o n e*) m a llo c (s iz eo f(p h o n e)* 1 0 0 );
int iS elec tio n = 0 ;
if ( p h o n e b o o k = = N U LL )
{
p rin tf( "O u t o f M em o ry. T h e p ro g ra m w ill n o w e xit");
re tu rn 1 ;
}
els e {}
do
{
p rin tf( "\ n \t\ t\ tP h o n eb o o k M e n u ");
p rin tf( "\ n \n \ t(1 )\ tA d d F rie n d ");
p rin tf( "\ n \t(2 )\tD elete F rien d ");
p rin tf( "\ n \t(3 )\tD is p la y P h o ne b o o k E n tries ");
p rin tf( "\ n \t(4 )\tS e a rc h f o r P h o n e N u m b er");
p rin tf( "\ n \t(5 )\tE xit P h o n eb o o k ");
p rin tf( "\ n \n W ha t w o u ld yo u lik e to d o ? ");
s c a n f("% d ", & iS e le c tio n );
if ( iS e lec tio n = = 1 )
{
A d d E n try(p h o n eb o o k );
}
if ( iS e lec tio n = = 2 )
{
D e le teE n try(p h o n eb o o k );
}
if ( iS e lec tio n = = 3 )
{
P rin tE n try (p h o ne b o o k );
}
if ( iS e lec tio n = = 4 )
{
S ea rc h F o rN u m b e r(p h o n e b o o k );
}
if ( iS e lec tio n = = 5 )
{
p rin tf( "\ n Y o u h a v e c h o s en to e xit th e P h o n e b o o k .\ n ");
re tu rn 0 ;
}
} w h ile (iS elec tio n < = 4 ) ;
}
v o id A d d E n try (p h o n e * p h o n eb o o k )
{
p W rite = f o p e n ("p h o n eb o o k _ c o n ta c ts .d a t", "a ");
if ( p W rite = = N U L L )
{
p e rro r("T h e fo llo w in g e rro r o c c u rred ");
ex it(E X IT _F A ILU R E );
}
els e
{
c o u n te r+ + ;
re a llo c (p h o n e b o o k , s ize o f (p h o ne ));
p rin tf( "\ n F irs t N a m e : ");
s c a n f("% s ", p h o n eb o o k [c o u n ter-1 ].F irs tN a m e );
p rin tf( "L a s t N a m e: ");
s c a n f("% s ", p h o n eb o o k [c o u n ter-1 ].La s tN a m e );
p rin tf( "P h o n e N u m b er (X X X -X X X -X X X X ): ");
s c a n f("% s ", p h o n eb o o k [c o u n ter-1 ].P h o n e N u m b e r);
p rin tf( "\ n \tF rien d s u c c e s s fu lly a d d ed to P h o n eb o o k \ n ");
fp rin tf (p W rite , "% s \ t% s \t% s \ n ", p h o n e b o o k [c o u n ter-1 ].F irs tN a m e,
p h o n eb o o k [c o u n te r-1 ]. La s tN a m e , p h o n eb o o k [c o un te r-1 ].P h o n eN u m b er);
fc lo s e(p W rite) ;
}
}
v o id D e leteE n try (p h o n e * p h o n eb o o k )
{
int x = 0 ;
int i = 0 ;
c h a r d e le te F irs tN a m e [2 0 ]; //
c h a r d e le te La s tN a m e [2 0 ];
p rin tf( "\ n F irs t n a m e : ");
s c a n f("% s ", d elete Firs tN a m e) ;
p rin tf( "L a s t n a m e: ") ;
s c a n f("% s ", d elete La s tN a m e );
fo r (x = 0 ; x < c o u n ter; x + + )
{
if ( s trc m p (d e le teF irs tN a m e , p h o n eb o o k [x].F irs tN a m e ) = = 0 )
{
if ( s trc m p (d e le teLa s tN a m e, p ho n eb o o k [x].La s tN a m e ) = = 0 )
{
fo r ( i = x; i < c o u n ter - 1 ; i+ + )
{
s trc p y(p h o n e b o o k [i].F irs tN a m e, p h o n e b o o k [i+ 1 ].F irs tN a m e);
s trc p y(p h o n e b o o k [i].L a s tN a m e, p h o n e b o o k [i+ 1 ].L a s tN a m e) ;
s trc p y(p h o n e b o o k [i].P h o n eN u m b er, p h o n eb o o k [i+ 1 ].P h o n e N u m b er);
}
p rin tf( "R ec o rd d e leted f ro m th e p h o n eb o o k .\n \ n ");
--c o u n ter;
re tu rn ;
}
}
}
p rin tf( "T h a t c o n ta c t w a s n o t fo u n d , p lea s e try a g a in. ") ;
}
v o id P rin tE n try ( p h o n e * p h o n e b o o k )
{
int x = 0 ;
p rin tf( "\ n P h o n e b o o k E n trie s :\ n \ n ");
p R ea d = fo p en ( "p h o n e b o o k _c o n ta c ts .d a t", "r");
if ( p R e a d = = N U LL )
{
p e rro r("T h e fo llo w in g e rro r o c c u rred : ");
ex it(E X IT _F A ILU R E );
}
els e
{
fo r( x = 0 ; x < c o u n ter; x + + )
{
p rin tf( "\ n (% d )\n ", x + 1 );
p rin tf( "N a m e: % s % s \ n ", p h o n e b o o k [x ].F irs tN a m e, p h o n eb o o k [x ].L as tN a m e);
p rin tf( "N u m b e r: % s \ n ", p h o n e b o o k [x ].P h o ne N u m b er);
}
}
fc lo s e(p R e a d );
}
v o id S ea rc h F o rN u m b e r (p h o n e * p h o n e b o o k )
{
int x = 0 ;
c h a r T em p F irs tN a m e[2 0 ];
c h a r T em p L a s tN a m e[2 0 ];
p rin tf( "\ n P le a s e typ e th e n a m e o f th e f rie n d yo u w is h to fin d a n u m b er fo r.");
p rin tf( "\ n \n F irs t N a m e: ");
s c a n f("% s ", T e m p F irs tN a m e );
p rin tf( "L a s t N a m e: ");
s c a n f("% s ", T e m p La s tN a m e );
fo r (x = 0 ; x < c o u n ter; x + + )
{
if ( s trc m p (T em p F irs tN a m e, p h o n eb o o k [x ].F irs tN a m e) = = 0 )
{
if ( s trc m p (T em p L a s tN a m e, p h o n e b o o k [x ].L a s tN a m e) = = 0 )
{
p rin tf( "\ n % s % s 's p h o n e n u m b er is % s \n ", p h o n eb o o k [x]. F irs tN a m e ,
p h o n eb o o k [x].La s tN a m e , p h o n eb o o k [x].P h o n eN u m b e r) ;
}
}
}
}

OUTPUT
P h o n eb o o k M e n u
(1 ) A d d Frien d
(2 ) D ele te Frien d "
(3 ) D is p la y Ph o n eb o o k E n tries
(4 ) Se a rc h fo r P h o n e N u m b e r
(5 ) E xit P h o n eb o o k

W h a t w o u ld yo u lik e to d o ? 1
F irs t N a m e: R a m
La s t N a m e : M o h a n
P h o n e N u m b e r (X X X -X X X -X X X X ) : 7 1 7 -6 7 5 -0 9 0 9
F rie n d s u c c es s f u lly a d d ed to P h o n eb o o k

P h o n eb o o k M e n u
(1 ) A d d Frien d
(2 ) D ele te Frien d "
(3 ) D is p la y Ph o n eb o o k E n tries
(4 ) Se a rc h fo r P h o n e N u m b e r
(5 ) E xit P h o n eb o o k

W h a t w o u ld yo u lik e to d o ? 5
Y o u h a v e c h o s en to ex it th e P h o n e b o o k .

RESULT
T h u s a C P ro g ra m w a s e xe c u ted a n d th e o u tp u t w a s o b ta in e d .

CONTENT BEYOND SYLLABUS


EX NO:13 BANKING APPLICATION

AIM
T o w rite a C P ro g ra m to C o u n t th e nu m b er o f a c c o u n t h o ld ers w h o s e b a la n c e is
les s th a n th e m in im u m b a la n c e u s in g s eq u en tia l a c c e s s f ile .

ALGORITHM
S te p 1 . S ta rt
S te p 2 . D e c la re v a ria b le s a n d f ile p o in ter.
S te p 3 . D is p la y th e m en u o p tio n s .
S te p 4 . R e a d th e In p u t fo r tra n s a c tio n p ro c e s s in g .
S te p 5 . C h e c k th e v alid a tio n fo r th e in p u t d a ta .
S te p 6 . D is p la y th e o u tp u t o f th e c a lc u la tio n s .
S te p 7 . R e p e a t s tep 3 u n til c h o o s e to s to p .
S te p 8 . S to p

PROGRAM
/ * C o u n t th e n u m b e r o f a c c o u n t h o ld e rs w h o s e b a la nc e is le s s th a n th e m in im u m b a la n c e
u s in g s eq u en tia l a c c e s s file. */
# in c lu d e < s td io . h >
# in c lu d e < s td lib .h >
# in c lu d e < c o n io .h >
# in c lu d e < s trin g .h >
# d efin e M IN B A L 5 0 0
s tru c t B a n k _ A c c o u n t
{
c h a r n o [1 0 ];
c h a r n a m e [2 0 ];
c h a r b a la n c e [1 5 ];
};
s tru c t B a n k _ A c c o u n t a c c ;
v o id m a in ()
{
lo n g in t p o s 1 ,p o s 2 ,p o s ;
F ILE *fp ;
c h a r *a n o ,*a m t;
c h a r c h o ic e;
int typ e ,fla g = 0 ;
flo a t b a l;
do
{
c lrs c r();
fflu s h (s td in );
p rin tf( "1 . A d d a N e w A c c o u n t H o ld er\ n ");
p rin tf( "2 . D is p la y\ n ");
p rin tf( "3 . D e p o s it o r W ith d ra w \n ");
p rin tf( "4 . N um b er o f A c c o u n t H o ld e r W h o s e B a la n c e is les s tha n th e M in im u m
B a la n c e\ n ");
p rin tf( "5 . S to p \ n ") ;
p rin tf( "E n te r yo u r c h o ic e : ");
c h o ic e= g etc h a r();
s w itc h ( c h o ic e)
{
c a s e '1 ' :
fflu s h (s td in );
fp = fo p e n ("a c c .d a t","a ");
p rin tf( "\ n E n ter the A c c o u n t N u m b er : ");
g e ts ( ac c . n o );
p rin tf( "\ n E n ter the A c c o u n t H o ld e r N a m e : ");
g e ts ( ac c . n a m e );
p rin tf( "\ n E n ter the In itia l A m o u n t to d ep o s it : ") ;
g e ts ( ac c . b a la n c e );
fs ee k (fp ,0 ,2 );
fw rite(& a c c ,s iz eo f(a c c ),1 ,fp );
fc lo s e(fp );
b rea k ;
c a s e '2 ' :
fp = fo p e n ("a c c .d a t","r");
if(fp = = N U LL)
p rin tf( "\ n F ile is E m p ty");
els e
{
p rin tf( "\ n A / c N u m b er\ tA /c H o ld er N a m e B a la n c e\ n ");
w hile( fre a d ( & a c c ,s iz eo f(a c c ),1 ,fp )= = 1 )
p rin tf( "% -1 0 s \t\ t% -2 0 s \t% s \ n ",a c c .n o ,a c c .n a m e ,a c c .b a la n c e) ;
fc lo s e(fp );
}
b rea k ;
c a s e '3 ' :
fflu s h (s td in );
fla g = 0 ;
fp = fo p e n ("a c c .d a t","r+ ") ;
p rin tf( "\ n E n ter the A c c o u n t N u m b er : ");
g e ts ( an o );
fo r(p o s 1 =f te ll(f p );frea d (& a c c ,s ize o f( a c c ) ,1 ,fp )= = 1 ;p o s 1 = ftell(fp ))
{
if(s trc m p (a c c .n o ,a n o )= = 0 )
{
p rin tf( "\ n E n ter the T yp e 1 fo r d e p o s it & 2 f o r w ith d ra w : ") ;
s c a n f("% d ",& typ e) ;
p rin tf( "\ n Y o u r C u rren t B ala n c e is : % s ",a c c .b a lan c e) ;
p rin tf( "\ n E n ter the A m o u n t to tra n s a c t : ");
fflu s h (s td in );
g e ts ( am t);
if(typ e= = 1 )
b a l = a to f (a c c .b a la n c e) + a to f( am t);
els e
{
b a l = a to f (a c c .b a la n c e) - a to f(a m t);
if(b a l< 0 )
{
p rin tf( "\ n R s .% s N o t a v a ila b le in yo ur A / c \ n ",a m t);
fla g = 2 ;
b rea k ;
}
}
fla g + + ;
b rea k ;
}
}
if(fla g = = 1 )
{
p o s 2 = ftell(fp );
p o s = p o s 2 -p o s 1 ;
fs ee k (fp ,-p o s ,1 );
s p rin tf( a m t,"% .2 f",b a l);
s trc p y(a c c .b a la nc e,a m t);
fw rite(& a c c ,s iz eo f(a c c ),1 ,fp );
}
els e if(fla g = = 0 )
p rin tf( "\ n A / c N u m b er N o t e xits ... C h ec k it a g a in ") ;
fc lo s e(fp );
b rea k ;
c a s e '4 ' :
fp = fo p e n ("a c c .d a t","r");
fla g = 0 ;
w hile( fre a d ( & a c c ,s iz eo f(a c c ),1 ,fp )= = 1 )
{
b a l = a to f (a c c .b a la n c e);
if(b a l< M IN B A L)
fla g + + ;
}
p rin tf( "\ n T h e N u m b er o f A c c o u n t H o ld er w h o s e B a la nc e les s th a n th e M in im u m B a la n c e :
% d ",fla g );
fc lo s e(fp );
b rea k ;
c a s e '5 ' :
fc lo s e(fp );
ex it(0 );
}
p rin tf( "\ n P re s s a n y k e y to c o n tin u e.. ..");
g e tc h ();
} w h ile (c h o ic e != '5 ');
}
OUTPUT
1 . A d d a N ew A c c o u n t H o ld er
2 . D is p la y
3 . D ep o s it o r W ith d ra w
4 . N u m b e r o f A c c o u n t H o ld e r W h o s e B a la n c e is le s s th a n th e M in im um B a la n c e
5 . S to p
E n te r yo u r c h o ic e : 1
E n ter th e A c c o u n t N u m b er : 5 4 7 8 9 8 7 6 0
E n ter th e A c c o u n t H o ld e r N a m e : R a ja n
E n ter th e In itia l A m o u n t to d ep o s it : 2 0 0 0
P res s a n y k ey to c o n tin u e. ...
1 . A d d a N ew A c c o u n t H o ld er
2 . D is p la y
3 . D ep o s it o r W ith d ra w
4 . N u m b e r o f A c c o u n t H o ld e r W h o s e B a la n c e is le s s th a n th e M in im um B a la n c e
5 . S to p
E n ter yo u r c h o ic e : 4
T h e N u m b er o f A c c o u n t H o ld er w h o s e B a la n c e le s s th a n th e M in im u m B a la n c e : 0
RESULT
T h u s a C P ro g ra m fo r B a n k in g A p p lic a tio n w a s e xe c u ted a n d th e o u tp u t w a s
o b ta in e d .

EX NO: 14 RAILWAY RESERVATION SYSTEM:

AIM
C re ate a R ailw a y re s erva tio n s ys tem in C w ith th e fo llo w in g m o d u le s
· B o o k in g
· A va ila b ility c h e c k in g
· C a n c e lla tio n
· P rep a re c h a rt
.
ALGORITHM
S te p 1 . S ta rt
S te p 2 . D e c la re v a ria b le s
S te p 3 . D is p la y th e m en u o p tio n s
S te p 4 . R e a d th e o p tio n .
S te p 5 . D e ve lo p th e c o d e fo r ea c h o p tio n .
S te p 6 . D is p la y th e o u tp u t o f th e s e le c te d o p tio n b a s ed o n e xis ten c e .
S te p 7 . S to p
PROGRAM
# in c lu d e< s td io .h >
# in c lu d e< c o n io . h >
in t firs t= 5 ,s e c o n d = 5 ,th ired = 5 ;
s tru c t n o d e
{
in t tic k e tn o ;
in t p h o n en o ;
c h a r n a m e [1 0 0 ];
c h a r a d d re s s [1 0 0 ];
}s [1 5 ];
in t i= 0 ;
v o id b o o k in g ( )
{
p rin tf("en ter yo u r d eta ils ");
p rin tf("\n n a m e:");
s c a n f ("% s ",s [i].n a m e);
p rin tf("\n p ho n en u m b e r:");
s c a n f ("% d ",& s [i].p h o n e n o );
p rin tf("\n a d d res s :");
s c a n f ("% s ",s [i].a d d res s );
p rin tf("\n tic k etn u m b e r o nly 1 -1 0 :");
s c a n f ("% d ",& s [i].tic k e tn o );
i+ + ;
}
v o id a va ila b ility()
{
in t c ;
p rin tf("av a ila b ility c h e k in g ") ;
p rin tf("\n 1 .firs t c la s s \ n 2 .s e c o n d c la s s \ n 3 .th ire d c la s s \ n ") ;
p rin tf("en ter th e o p tio n ");
s c a n f ("% d ",& c ) ;
s w itc h (c )
{
c a s e 1 :if(firs t> 0 )
{
p rin tf( "s e a t a v a ila b le \n ");
firs t--;
}
els e
{
p rin tf( "s e a t n o t a va ila b le ");
}
b rea k ;
c a s e 2 : if (s ec o n d > 0 )
{
p rin tf( "s e a t a v a ila b le \n ");
s ec o n d --;
}
els e
{
p rin tf( "s e a t n o t a va ila b le ");
}
b rea k ;
c a s e 3 :if(th ire d > 0 )
{
p rin tf( "s e a t a v a ila b le \n ");
th ired --;
}
els e
{
p rin tf( "s e a t n o t a va ila b le ");
}
b rea k ;
d e fa u lt:

b rea k ;
}
}
v o id c a n c el()
{
in t c ;
p rin tf("c a n c e l\n ");
p rin tf("w h ic h c la s s yo u w a n t to c a n c e l");
p rin tf("\n 1 .firs t c la s s \ n 2 .s e c o n d c la s s \ n 3 .th ire d c la s s \ n ") ;
p rin tf("en ter th e o p tio n ");
s c a n f ("% d ",c );
s w itc h (c )
{
ca se 1:
firs t+ + ;
b rea k ;
ca se 2:
s ec o n d + + ;
b rea k ;
ca se 3:
th ired + + ;
b rea k ;
d e fa u lt:
b rea k ;
}
p rin tf("tic k e t is c a n c eled ");
}
v o id c h a rt()
{
in t c ;
fo r(c = 0 ;c < I;c + + )
{
p rin tf(“ \n T ic k e t N o \ t N a m e\ n ” );
p rin tf(“ % d \t% s \ n ” ,s [c ].tic k e tn o ,s [c ].n a m e)
}
}
m a in ()
{
in t n ;
c lrs c r();
p rin tf("w e lc o m e to ra ilw a y tic k et re s erv a tio n \ n ");
w h ile (1 ) {
p rin tf("1 .b o o k in g \n 2 .a va ila b ility c he k in g \ n 3 .c a n c e l\ n 4 . C h a rt \ n 5 . E xit\n e n te r yo u r
o p tio n :");
s c a n f ("% d ",& n );
s w itc h (n )
{
c a s e 1 : b o o k in g ();
b rea k ;
c a s e 2 : a va ila b ility();
b rea k ;
c a s e 3 : c a n c el();
b rea k ;
ca se 4:
c h a rt();
b re a k ;
ca se 5:
p rin tf( “ \n T h a n k y o u vis it a g a in !” );
g e tc h ();
ex it(0 );
d e fa u lt:
b rea k ;
}
}
g e tc h ();
}

OUTPUT
w elc o m e to ra ilw a y tic k e t res e rva tio n
1 . b o o k in g
2 . a va ila b ility c h e k in g
3 . c a n c el
4 . C h a rt
5 . E xit
en te r yo ur o p tio n : 2
a va ila b ility c h ek in g
1 . firs t c la s s
2 . s ec o n d c la s s
3 . th ired c la s s
en te r th e o p tio n 1
s ea t a va ila b le
1 . b o o k in g
2 . a va ila b ility c h e k in g
3 . c a n c el
4 . C h a rt
5 . E xit
en te r yo ur o p tio n : 5
T h a n k yo u vis it a g a in !
RESULT
T h u s a C P ro g ra m fo r R a ilw a y re s erv a tio n s ys te m w a s ex ec u te d a n d th e o u tp u t
w as
o b ta in e d .

EX NO:15 COUNT THE NUMBER OF ACCOUNT HOLDERS WHOSE BALANCE IS


LESS THAN THE MINIMUM BALANCE USING SEQUENTIAL ACCESS FILE.

AIM
T o d ev elo p a C p ro g ra m to C o u n t th e n u m b e r o f a c c o u n t h o ld ers w h o s e b ala n c e is
les s th a n th e m in im u m b a la n c e u s in g s eq u en tia l a c c e s s f ile .

ALGORITHM
S te p 1 . S ta rt
S te p 2 . D e c la re v a ria b le s
S te p 3 . D is p la y th e m en u o p tio n s
S te p 4 . R e a d th e R e c o rd s .
S te p 5 . D e ve lo p th e c o d e fo r ea c h o p tio n .
S te p 6 . D is p la y th e o u tp u t o f th e s e le c te d o p tio n b a s ed o n e xis ten c e.
S te p 7 . S to p

PROGRAM

# in c lu d e < s td io . h >
typ e d e f s tru c t
{
in t u s n ;
c ha r n a m e [2 5 ];
in t m 1 ,m 2 ,m 3 ;
}S T D ;
STD s;
v o id d is p la y(F ILE *) ;
in t s e a rc h (F IL E *,in t);
v o id m a in ()
{
in t i,n ,u s n_ k e y,o p n ;
F IL E *fp ;
p rin tf(" H o w m a n y R ec o rd s ? ");
s c an f ("% d ",& n );
fp = fo p en ("s tu d .d a t","w ") ;
fo r(i= 0 ;i< n ;i+ + )
{
p rin tf("R ea d th e In fo fo r S tu d e n t: % d (u s n ,n a m e ,m 1 ,m 2 ,m 3 ) \n ",i+ 1 );
s c a nf ("% d % s % d % d % d ",& s .u s n ,s .n a m e,& s . m 1 ,& s .m 2 ,& s .m 3 );
fw rite (& s ,s ize o f(s ) ,1 ,fp );
}
fc lo s e( fp );
fp = fo p en ("s tu d .d a t","r") ;
do
{
p rin tf("Pre s s 1 - D is p la y\ t 2 - S ea rc h \ t 3 - E x it\ t Y o u r O p tio n ? ");
s c a nf ("% d ",& o p n );
s w itc h (o p n )
{
c a s e 1 : p rin tf( "\ n Stu d en t R ec o rd s in th e F ile \ n ") ;
d is p lay (fp );
b re a k ;
c a s e 2 : p rin tf( " R e a d th e U S N o f th e s tu d e n t to b e s ea rc h e d ? ") ;
s c a n f("% d ",& u s n _ k ey);
if(s e a rc h (fp ,u s n _k e y))
{
p rin tf("S u c c es s ! R ec o rd fo u nd in th e file\ n ") ;
p rin tf("% d \ t% s \ t% d \ t% d \ t% d \ n ",s .u s n ,s .n a m e,s .m 1 ,s .m 2 ,s .m 3 );
}
e ls e
p rin tf(" F a ilu re!! R ec o rd w ith U S N % d n o t fo u n d \ n ",u s n_ k e y);
b re a k ;
c a s e 3 : p rin tf(" E x it!! P res s a k ey . . .");
g etc h ();
b re a k ;
d efa u lt: p rin tf( " In v a lid O p tio n !!! T ry ag a in !!!\n ");
b re a k ;
}
}w h ile( o p n != 3 );
fc lo s e( fp );
} / * E n d o f m a in () */
v o id d is p la y(F ILE *f p )
{
rew in d (fp );
w h ile (frea d (& s ,s ize o f( s ),1 ,fp ) )
p rin tf("% d \ t% s \t% d \t% d \t% d \n ",s . u s n ,s .n a m e,s .m 1 ,s .m 2 ,s .m 3 );
}
in t s e a rc h (F IL E *fp , in t u s n _k e y)
{
rew in d (fp );
w h ile (frea d (& s ,s ize o f( s ),1 ,fp ) )
if( s .u s n = = us n _ k ey ) re tu rn 1 ;
retu rn 0 ;
}

RESULT
T h u s a C P ro g ra m to C o u n t th e n u m b er o f a c c o u n t h o ld ers w h o s e b a la n c e is les s
th a n th e m in im u m b a la n c e u s in g s e q u en tia l a c c es s file w a s e xe c u te d a n d th e o u tp u t w a s
o b ta in e d .

EX NO:16 TELEPHONE DIRECTORY THAT PROVIDES APPEND, FIND AND


DISPLAY ALL RECORDS FROM A FILE

AIM
T o d ev elo p a C p ro g ra m th a t p ro vid es a p p en d , fin d a n d d is p la y a ll re c o rd s f ro m a
file fo r T ele p h o n e D ire c to ry.
ALGORITHM
S te p 1 . S ta rt
S te p 2 . D e c la re v a ria b le s
S te p 3 . D is p la y th e m en u o p tio n s
S te p 4 . R e a d th e R e c o rd s .
S te p 5 . D e ve lo p th e c o d e fo r ea c h o p tio n .
S te p 6 . D is p la y th e o u tp u t o f th e s e le c te d o p tio n b a s ed o n e xis ten c e.
S te p 7 . S to p

PROGRAM

# in c lu d e < s td io . h >
# in c lu d e < c o n io .h >
# in c lu d e < s trin g .h >
s tru c t p ers o n {
c h a r n a m e [2 0 ];
lo n g teln o ;
};
v o id a p p en d D a ta (){
F ILE * fp ;
s tru c t p e rs o n o b j;
c lrs c r();
fp = fo p e n ("d a ta. tx t","a ");
p rin tf("*****A d d R ec o rd ** **\n ");
p rin tf("E nte r N a m e : ");
s c a n f("% s ",o b j. n a m e );
p rin tf("E nte r T ele p h o n e N o . : ");
s c a n f("% ld ",& o b j. te ln o );
fp rin tf( fp ,"% 2 0 s % 7 ld ",o b j.n a m e,o b j.teln o ) ;
fc lo s e (fp );
}
v o id s h o w A llD a ta (){
F ILE * fp ;
s tru c t p e rs o n o b j;
c lrs c r();
fp = fo p e n ("d a ta. tx t","r");
p rin tf("*****D is p la y A ll R ec o rd s ***** \n ");
p rin tf("\ n \n \ t\ tN a m e \t\ t\ tT e lep h o n e N o . ");
p rin tf("\ n \t\ t= = = = = \ t\ t\t= = = = = = = = == = = = = = \ n \n ");
w h ile(!fe o f( fp ))
{
fs c a n f(f p ,"% 2 0 s % 7 ld ",o b j.n a m e,& o b j.teln o );
p rin tf("% 2 0 s % 3 0 ld \ n ",o b j.n a m e,o b j.teln o ) ;
}
fc lo s e (fp );
g etc h ();
}
v o id fin d D a ta () {
F ILE * fp ;
s tru c t p e rs o n o b j;
c h a r n a m e[2 0 ];
in t to tre c = 0 ;
c lrs c r();
fp = fo p e n ("d a ta. tx t","r");
p rin tf("*****D is p la y Sp ec ific R e c o rd s *****\ n ") ;
p rin tf("\ n E n ter N a m e : ") ;
s c a n f("% s ",& n a m e);
w h ile(!fe o f( fp ))
{
fs c a n f(f p ,"% 2 0 s % 7 ld ",o b j.n a m e,& o b j.teln o );
if(s trc m p i(o b j.n a m e,na m e )= = 0 ){
p rin tf("\n \ n N am e : % s ",o b j.n a m e );
p rin tf("\n T e le p h o n e N o : % ld ",o b j.teln o );
to trec + + ;
}
}
if( to tre c = = 0 )
p rin tf ("\ n \ n\ n N o D a ta F o u n d ");
els e
p rin tf ("\ n \ n= = = T o ta l % d R ec o rd fo u n d = = = ",to tre c );
fc lo s e (fp );
g etc h ();
}
v o id m a in () {
c h a r c h o ic e;
w h ile(1 ){
c lrs c r();
p rin tf("*****T E L E P H O N E D IR E C T O R Y *****\ n \ n ");
p rin tf("1 ) A p p e n d R e c o rd \n ");
p rin tf("2 ) F in d R e c o rd \n ");
p rin tf("3 ) R e a d a ll rec o rd \ n ");
p rin tf("4 ) ex it\ n ");
p rin tf("E n ter yo u r c h o ic e : ");
fflu s h (s td in );
c ho ic e = g etc h e ();
s w itc h (c h o ic e) {
c a s e '1 ' : / /c a ll a p p en d re c o rd
a p p en d D a ta ();
b re a k ;
c a s e '2 ' : / /c a ll fin d rec o rd
fin d D a ta ();
b re a k ;
c a s e '3 ' : / /R ea d a ll re c o rd
s h o w A llD ata ();
b re a k ;
c a s e '4 ' :
c a s e 2 7 : e xit(1 ) ;
}
}
}

OUTPUT
RESULT
T h u s a C Pro g ra m th a t p ro v id es a p p en d , fin d a n d d is p la y a ll re c o rd s fro m a file fo r
T ele p h o n e D ire c to ry w a s ex ec u te d a n d th e o u tp u t w a s o b tain e d .
VIVA QUESTIONS

1 . W h at is C la n g u a g e ?
C is a p ro g ra m m in g la n g u a g e d ev elo p ed a t A T & T 's B e ll L ab o ra to ries o f U S A in
1 9 7 2 . T h e C p ro g ra m m in g la n g u a g e is a s ta nd a rd ize d p ro g ra m m in g la ng u a g e d ev elo p e d
in th e e arly 1 9 7 0 s b y K en T h o m p s o n a n d D en n is R itc h ie fo r us e o n th e U N IX o p e ra tin g
s ys tem . It h a s s in c e s p re a d to m a n y o th e r o p era tin g s ys te m s , a n d is o n e o f th e m o s t
w id ely u s ed p ro g ra m m in g la n g u a g es .

2 . W h at a re th e typ es o f c o n s ta n ts in C ?
In C la n g u a g e tw o typ es o f c o n s ta n ts a re a va ila b le :
? P rim a ry c o n s ta n ts
? S e c o n d a ry c o n s ta n ts

3 . W h at a re th e typ es o f C in s tru c tio n s ?


T h ere a re b a s ic a lly th re e typ e s o f in s tru c tio n s in C :
? T yp e D e c la ra tio n In s tru c tio n
? A rith m e tic In s tru c tio n
? C o n tro l In s tru c tio n

4 . W h at is a p o in te r?
P o in ters a re v a ria b le s w h ic h s to res th e a d d re s s o f a n o th er va ria b le. T h a t v a ria b le
m a y b e a s c a la r (in c lu d in g a n o the r p o in te r), o r a n a g g re g a te (a rra y o r s truc tu re ). T h e
p o in te d -to o b jec t m a y b e p a rt o f a la rg er o b je c t, s u c h a s a f ie ld o f a s tru c tu re o r a n
ele m e n t in a n a rra y.

5 . W h at is a n a rra y?
A rra y is a va ria b le th a t h o ld m u ltip le elem e nts w h ic h h a s th e s a m e d a ta ty p e.

6 . D iffere ntia te b e tw e en a rra ys a n d p o in te rs ?


P o in ters a re u s ed to m a n ip u la te d a ta u s in g th e a d d re s s . P o in ters us e * o p era to r to
a c c es s the d a ta p o in te d to b y th em .A rra y is a c o lle c tio n o f s im ilar d a ta typ e . A rra y u s e
s u b s c rip te d va ria b les to a c c e s s a n d m a n ip u la te d a ta . A rra y v a ria b le s c a n b e e q u iva le n tly
w ritten u s in g p o in ter ex p res s io n .

7 . W h at is “ th is ” p o in ter?
T h e “ th is ” p o in ter is a p o in ter a c c e s s ib le o n ly w ith in th e m em b e r fu n c tio n s o f a
c la s s , s tru c t,o r u nio n typ e . It p o in ts to th e o b je c t fo r w h ic h th e m e m b er fu n c tio n is c a lled .
S ta tic m em b e r f un c tio n s d o n o t h a ve a “ th is ” p o in ter.

8 . W h at a re th e u s es o f a p o in te r?
P o in ter is u s e d in th e fo llo w in g c a s es
? It is u s e d to a c c es s a rra y e le m en ts .
? It is u s e d fo r d yn a m ic m em o ry a llo c a tio n .
? It is u s e d in C a ll b y re feren c e.
? It is u s e d in d a ta s tru c tu re s lik e tree s , g ra p h , lin k ed lis t etc .

9 . W h at is th e p u rp o s e o f m ain () fu n c tio n ?
T h e fu n c tio n m a in( ) in vo k es o th e r fu n c tio n s w ith in it. It is th e firs t fu n c tio n to b e
c a lled w h e n th e p ro g ra m s ta rts e xe c u tio n .
? It is th e s ta rtin g fu n c tio n .
? It retu rn s a n in t va lu e to th e e n viro n m en t th a t c a lle d th e p ro g ra m .
? R ec u rs iv e c a ll is a llo w ed f o r m a in ( ) a ls o .
? It is a u s e r-d ef in e d fu n c tio n .

1 0 . W h a t a re th e d iff eren t s to ra g e c la s s e s in C ?
T h ere a re fo u r typ e s o f s to ra g e c la s s es in C la n g ua g e.
? A u to m a tic
? E xtern
? R eg is ter
? S ta tic

1 1 . W h a t is a s tru c tu re?
S tru c tu re c o n s titu tes a s u p e r d a ta typ e w h ic h rep re s en ts s e ve ral d iffe re n t d a ta
typ e s in a s in g le u n it. A s tru c tu re c a n b e in itia lize d if it is s ta tic o r g lo b a l.

1 2 . D e fin e C o n s tru c to rs ?
A c o n s tru c to r is a m em b er f u n c tio n w ith th e s a m e n a m e a s its c la s s . T h e
c o n s tru c to r is in vo k ed w h e n ev er a n o b jec t o f its a s s o c ia te d c la s s is c rea ted . It is c a lle d
c o n s tru c to r b e c a u s e it c o n s tru c ts th e va lu es o f d a ta m em b ers o f the c la s s .

1 3 . D e fin e d e s tru c to rs ?
A d e s tru c to r is c a lled fo r a c las s o b je c t w h en th a t o b jec t p a s s e s o u t o f s c o p e o r is
ex p lic itly d e le ted . A d es tru c to rs a s th e n a m e im p lies is u s e d to d e s tro y th e o b jec ts th a t
h a ve b e en c re a ted b y a c o n s tru c to rs . Lik e a c o n s tru c to r, th e d es tru c to r is a m e m b er
fu n c tio n w h o s e n am e is th e s a m e a s th e c la s s n a m e b u t is p re c e d e d b y a tild e.

1 4 . W h a t is th e u s e o f d efa u lt c o n s tru c to r?
A c o n s tru c to r th at a c c ep ts n o p a ra m e te rs is c a lle d the d ef a ult c o n s tru c to r. If n o
u s erd efin ed c o n s tru c to r ex is ts fo r a c la s s A a n d o n e is n ee d ed , th e c o m p ile r im p lic itly
d e c la res a d efa u lt p a ra m e ter les s c o n s tru c to r A ::A (). T h is c o n s tru c to r is a n in lin e p u b lic
m em b e r o f its c la s s . T h e c o m p iler w ill im p lic itly d e fin e A ::A () w h en th e c o m p iler u s es th is
c o n s tru c to r to c re a te a n o b je c t o f ty p e A . T h e c o n s tru c to r w ill h a ve n o c o n s tru c to r
in itia liz er a n d a n u ll b o d y.

1 5 . W h a t is a m a c ro ?
M a c ro s a re the id en tifiers th a t re p res e n t s ta tem en ts o r ex p res s io n s .

1 6 . W h a t is th e d iffe re n c e b e tw ee n # in c lu d e < > a n d # in c lu d e “ ” ?


# in c lu d e< > ----> s p ec ific a lly u s e d fo r b u ilt in h ea d er file s .
# in c lu d e “ ” ----> S p e c ific a lly u s e d fo r u s e d fo r u s er d e fin ed / c re a te d h ea d er file .

1 7 . W h a t a re th e a d va n ta g e s o f th e fu n c tio n s ?
? It red uc es th e C o m p lex ity in a p ro g ra m b y re d u c in g th e c o d e.
? F u n c tio n s a re e a s ily u n d e rs ta n d in g a n d re lia b ility a n d e xe c u tio n is f a s te r.
? It a ls o red u c e s th e T im e to ru n a p ro g ra m . In o th e r w a y, it’ s d irec tly
p ro p o rtio n a l to C o m p lex ity.
? It’ s ea s y to fin d -o ut th e erro rs d u e to th e b lo c k s m a d e a s fu n c tio n d e fin itio n
o u ts id e th e m a in f u n c tio n .

1 8 . H o w d o d ec la re a n a rra y?
W e c a n d e c la re a n a rray b y s p e c ify its d a ta ty p e, n a m e a n d th e n u m b e r o f
ele m e n ts th e a rra y h o ld s b etw ee n s q u a re b ra c k e ts im m e d ia te ly fo llo w in g th e a rra y n a m e .
s yn ta x : d a ta_ typ e a rra y_n a m e[s iz e];

1 9 . W h a t a re th e d iff eren c es b e tw e en s tru c tu re s a n d u n io n ?


A s tru c tu re v aria b le c o n ta in s ea c h o f th e n a m ed m em b e rs , a n d its s ize is la rg e
en o u g h to h o ld a ll th e m e m b ers . S tru c tu re e le m en ts a re o f s a m e s iz e.
A U n io n c o n ta in s o n e o f th e n a m ed m e m b ers a t a g ive n tim e a n d is la rg e en o u g h
to h o ld th e la rg es t m em b e r. U n io n e lem en t c a n b e o f d iffe ren t s iz es .

2 0 . W h a t is th e d iffe re n c e b e tw ee n a n A rra y a n d a Lis t?


T h e m a in d iffe ren c e b etw e en an a rra y a n d a lis t is h o w th ey in tern a lly s to re th e
d a ta w h e rea s A rra y is c o llec tio n o f h o m o g e n eo u s e lem en ts . Lis t is c o llec tio n o f
h ete ro g e n eo us e le m en ts .

2 1 . W h a t is th e d iffe re n c e b e tw ee n a s trin g c o p y (s trc p y) a n d a m em o ry c o p y (m em c p y)?


T h e s trc p y() fu n c tio n is d es ig n e d to w o rk ex c lu s iv ely w ith s tring s . It c o p ie s e a c h
b yte o f th e s o u rc e s trin g to th e d es tin a tio n s trin g a n d s to p s w h e n th e term in a tin g n ull
c h a ra c te r ( ) h a s b e en m o ve d .O n th e o th er h a n d , th e m em c p y() f un c tio n is d e s ig n ed to
w o rk w ith a ny typ e o f d a ta .
B ec a u s e n o t a ll d a ta e n d s w ith a n u ll c h a ra c te r, yo u m u s t p ro vid e th e m e m c p y( ) fu n c tio n
w ith th e n u m b er o f b yte s y o u w a n t to c o p y fro m th e s o u rc e to th e d e s tin a tio n .

2 2 . W h a t is th e d iffe re n c e b e tw ee n c o n s t c h a r*p a n d c h a r c o n s t* p ?
c o n s t c h a r*p - p is p o in te r to th e c o n s ta n t c h a ra c te r. i.e v a lu e in th a t a d d res s
lo c a tio n is c o ns ta n t.c o n s t c h a r* c o n s t p - p is th e c o n s ta n t p o in ter w h ic h p o in ts to th e
c o n s ta nt s trin g , b o th va lu e a n d a d d res s a re c o n s ta nts .

2 3 . W h a t is th e p u rp o s e o f rea llo c ()?


R e a llo c (p tr,n ) f u n c tio n u s es tw o a rg um e n ts .
? T h e firs t a rg u m en t p tr is a p o in te r to a b lo c k o f m e m o ry f o r w h ic h th e
s ize is to b e a lte re d .
? T h e s ec o n d a rg u m e n t n s p e c ifie s th e ne w s iz e. Th e s ize m a y b e
in c rea s e d o r d e c rea s e d .

2 4 . W h a t is th e u s e o f typ e d e f?
T h e typ e d e f h elp in ea s ier m o d ific a tio n w h en th e p ro g ra m s a re p o rte d to a n o th er
m a c h in e. A d e s c rip tive n ew n a m e g iv en to th e e xis tin g d a ta typ e m ay b e ea s ier to
u n d e rs ta n d th e c o d e.

2 5 . W h a t a re th e d iff eren c es b e tw e en n ew a n d m a llo c ?


? N e w in itia lize s th e allo c a ted m em o ry b y c a llin g th e c o n s tru c to r. M em o ry
a llo c a te d w ith n ew s h o u ld b e re lea s ed w ith d ele te .
? M a llo c a llo c a te s u n in itia lize d m e m o ry.
? T h e a llo c a te d m em o ry h a s to b e relea s e d w ith free . N ew a uto m a tic a lly c a lls th e
c o n s tru c to r w h ile m a llo c (d o s en ’ t)

2 6 . W h a t is th e d iffe re n c e b e tw ee n s trd u p a n d s trc p y?


B o th c o p y a s trin g . s trc p y w a n ts a b u ff er to c o p y th e s trin g . s trd u p a llo c a tes a
b u f fer u s in g m a llo c (). U n lik e s trc p y() , s trd u p () is n o t s p ec if ie d b y A N S I.

2 7 . W h a t is th is p o in te r?
It is a p o in te r th a t p o in ts to th e c u rren t o b je c t. T h is c a n b e u s ed to a c c es s th e
m em b e rs o f
th e c u rren t o b jec t w ith th e h elp o f th e a rro w o p era to r.

2 8 . W h a t is rec urs io n ?
A re c u rs io n f un c tio n is o ne w h ic h c a lls its e lf eith er d irec tly o r in d irec tly it m u s t h a lt
at a
d e fin ite p o in t to a v o id in fin ite re c u rs io n .

2 9 . W h a t a re th e c h a ra c te ris tic s o f a rra ys in C ?


? A n a rra y h o ld s elem e n ts th a t h a ve th e s a m e d a ta typ e .
? A rra y elem e n ts a re s to red in s u b s e q u e n t m em o ry lo c a tio n s
? T w o -d im e n s io n a l arra y elem en ts a re s to red ro w b y ro w in s u b s eq ue n t m em o ry
lo c a tio ns .
? A rra y n a m e re p res e n ts th e a d d res s o f th e s ta rtin g ele m e n t

3 0 . D iffe re n tia te b etw ee n fo r lo o p a n d a w h ile lo o p ? W h a t a re it u s es ?


F o r ex ec u tin g a s e t o f s ta tem en ts fix ed n u m b e r o f tim e s w e u s e fo r lo o p w h ile
w h en th e
n u m b er o f itera tio n s to b e p e rfo rm ed is n o t k n o w n in a d v a n c e w e u s e w h ile lo o p .

3 1 . W h a t is th e d iffe re n c e b e tw ee n p rintf(. ..) a n d s p rin tf(.. .)?


? p rin tf(.. ..) -------------> is s tan d a rd o u tp u t s ta tem e n t
? s p rin tf(.. .... )-----------> is fo rm a tte d o u tp ut s ta te m e n t.

3 2 . W h a t is a n ex p lic it c o n s tru c to r?
A c o n ve rs io n c o n s tru c to r d e c la red w ith th e ex p lic it k e yw o rd . T h e c o m p ile r d o es
n o t u s e an e xp lic it c o n s tru c to r to im p lem en t a n im p lie d c o n ve rs io n o f typ e s . E xp lic it
c o n s tru c to rs a re
s im p ly c o n s tru c to rs th a t c a n n o t ta k e p a rt in a n im p lic it c o n v ers io n .

3 3 . W h a t is c o p y c o n s tru c to r?
C o p y c o n s tru c to r is a c o n s tru c to r fu n c tio n w ith th e s a m e n a m e a s th e c la s s a n d
u s ed to
m a k e d e ep c o p y o f o b je c ts .

3 4 . W h a t is th e d iffe re n c e b e tw ee n m a llo c a n d c a llo c ?


? M a llo c () is u s e fo r m em o ry a llo c a tio n a n d in itia liz e g a rb a g e v a lu e s . m allo c () fo r
a llo c a tin g th e s in g le b lo c k o f m em o ry.
? C a llo c () is s a m e a s m a llo c ( ) b u t it in itia lize 0 v a lu e . c a llo c ( ) fo r a llo c a tin g
m u ltip le
b lo c k s o f m em o ry.

3 5 . W h a t is n u ll p o in te r?
N U L L p o inte r is a p o in ter w h ic h is p o in tin g to n o th in g .
E x a m p les :
V is it F o r M o re : w w w . Le a rn E n g in ee rin g .in
in t *p tr= (c h a r *)0 ;
flo a t *p tr= (flo a t *)0 ;

3 6 . W h a t is d yn a m ic a rra y?
T h e d yn a m ic a rra y is a n a rra y d a ta s tru c tu re w h ic h c a n b e res iz ed d u rin g run tim e
w h ic h
m ea n s ele m e n ts c an b e a d d ed a n d re m o ve d .

3 7 . W h a t a re m a c ro s ? W h a t a re its a d v a n ta g es a n d d is a d va n ta g e s ?
M a c ro s a re a b b re via tio n s fo r le n g th y a n d f re q u e n tly u s e d s ta tem en ts . W h e n a
m a c ro is
c a lled th e en tire c o d e is s u b s titu ted b y a s in g le lin e th o u g h th e m a c ro d efin itio n is o f
s ev era l lin e s .
T h e a d va n ta g e o f m a c ro is th at it re d u c e s th e tim e ta k en f o r c o n tro l tra n s fe r a s in
ca se of
fu n c tio n .
T h e d is a d va n ta g e o f it is h ere th e en tire c o d e is s u b s titu ted s o th e p ro g ra m
b e c o m e s le n g th y if a m a c ro is c a lled s e ve ra l tim e s .

3 8 . W h a t a re reg is te r v a ria b le s ? W h a t a re th e a d v a n ta g es o f u s in g reg is te r v a ria b le s ?


If a v a ria b le is d e c la red w ith a reg is te r s to ra g e c la s s , it is k n o w n a s re g is ter
v aria b le . Th e
reg is te r va ria b le is s to red in th e C P U re g is ter in s tea d o f m a in m e m o ry. F req u en tly u s e d
v aria b le s a re d ec la red a s re g is te r v a ria b le a s it’ s a c c es s tim e is fa s te r.

3 9 . W h a t is s to ra g e c la s s ? W h a t a re th e d iffe re n t s to ra g e c la s s es in C ?
S to ra g e c la s s is a n a ttrib u te th a t c h a n g es th e b eh a v io r o f a v a ria b le. It c o n tro ls th e
lifetim e ,s c o p e a n d lin k a g e . T h e s to ra g e c la s s e s in c a re a u to , reg is te r, a n d e xte rn , s ta tic ,
typ e d e f.

4 0 . W h a t th e a d va n ta g e s o f u s in g U n io n s ?
W h e n th e C c o m p iler is a llo c a tin g m e m o ry fo r u n io n s it w ill a lw a ys res e rv e en o u g h
ro o m
fo r th e la rg es t m e m b er.

4 1 . In C , w h y is th e v o id p o in te r u s e fu l? W h en w o u ld yo u u s e it?
T h e vo id p o in ter is u s e fu l b e c a u s e it is a g en e ric p o in te r th a t a n y p o in ter c a n b e
c a s t in to
a n d b a c k a g a in w ith o u t lo s s o f in fo rm a tio n .

4 2 . W h a t is th e d iffe re n c e b e tw ee n th e fu n c tio n s m e m m o ve () a n d m e m c p y( )?
T h e a rg u m e n ts o f m em m o v e() c a n o ve rla p in m e m o ry. T h e a rg um e n ts o f
m em c p y()
c a n n o t.

4 3 . C a n a S tru c tu re c o n ta in a P o in te r to its elf?


Y e s s u c h s tru c tu res a re c alled s elf-ref eren tia l s truc tu re s .

4 4 . W h a t is d yn a m ic m em o ry a llo c a tio n ?
A d yn am ic m em o ry a llo c a tio n u s es fu n c tio n s s u c h a s m a llo c () o r c a llo c () to g et
m em o ry
d yn a m ic a lly. If th e s e fu n c tio n s a re u s ed to g et m e m o ry d yn a m ic a lly a n d th e v a lu es
retu rn e d b y th e s e fu n c tio n a re a s s ig n ed to p o in ter va ria b les , s uc h a w a y o f a llo c a tin g
m em o ry a t ru n tim e is k n o w n a s d yn a m ic m em o ry a llo c a tio n .

4 5 . W h a t is p o inte r to a p o in ter?
If a p o in ter v a ria b le p o in ts a n o th er p o in ter va lu e. S u c h a s itu atio n is k n o w n a s a
p o in te r to a p o in ter.
E x a m p le :
in t *p 1 , **p 2 ,
v =1 0 ;
P 1=& v;
p2 =& p1 ;
H ere p 2 is a p o in te r to a p o in te r.

4 6 . W h a t is a fu n c tio n ?
A la rg e p ro g ra m is s u b d iv id ed in to a n u m b e r o f s m a ller p ro g ra m s o r s u b p ro g ra m s .
Eac h
s u b p ro g ra m s p ec ifies o n e o r m o re a c tio n s to b e p e rf o rm e d fo r th e la rg er p ro g ra m . S u c h
s u b p ro g ra m s a re c a lle d fu n c tio n s .

4 7 . W h a t is a n a rg u m e n t?
A n a rg u m en t is a n en tity u s e d to p a s s d a ta fro m th e c a llin g to a c a lled f un c tio n .

4 8 . W h a t is th e d iffe re n c e b e tw ee n s yn ta x vs lo g ic a l e rro r?
S yn ta x E rro r
? T h e s e in vo lv e v a lid a tio n o f s yn ta x o f la n g u a g e .
? C o m p iler p rin ts d ia g n o s tic m e s s a g e .
Lo g ic a l E rro r
? L o g ic a l e rro r a re c a u s e d b y a n in c o rrec t a lg o rith m o r b y a s ta tem en t m is typ e d in
such
a w a y th a t it d o e s n ’ t v io let s yn ta x o f la n g u a g e .
? D if fic u lt to fin d .
4 9 . D iffe re n tia te b etw ee n th e e xp re s s io n “ + + a ” and “ a+ +” ?
? W ith + + a , the in c re m e n t h ap p e n s firs t o n v a ria b le a , a n d th e re s u ltin g v a lu e is
u s ed .
T h is is c a lled a s p re fix in c rem e n t.
? W ith a + + , th e c u rren t va lu e o f th e v a ria b le w ill b e u s ed in a n o p e ra tio n . T h is is
c a lled a s
p o s tfix inc rem en t.

5 0 . W h a t is p rep ro c es s o r?
T h e p re p ro c es s o r is a p ro g ra m w h ic h is ex ec u ted b ef o re th e c o m p ila tio n o f a
s o u rc e
p ro g ra m w ritten b y th e u s er. T h e p re p ro c es s o r d ire c tiv es b eg in e s w ith h a s h (# ) fo llo w ed
b y th e c o m m a n d . e.g # in c lu d e – it is a d irec tiv e to in c lu d e file.

5 1 . W h a t is lva lu e a n d rva lu e ?
T h e e xp re s s io n a p p e a rin g o n rig h t s id e o f th e a s s ig n m en t o p e ra to r is c a lle d a s
rva lu e.
R v a lu e is a s s ig ne d to lva lu e, w h ic h a p p e a rs o n lef t s id e o f th e a s s ig n m e n t o p e ra to r.

You might also like