You are on page 1of 74

1

I
NDEX

S.
NO DATE NAMEOFTHEPROGRAM PAGE STAFF
NO SI
GNATURE
1 Thesum ofdi
git
s

2 TheAr
mst
rongorNot

3 CheckPr
imeorNot

4 TheFi
bonacciser
ies

5 TheAdam orNot

6 Rev
ersenumberandSt
ri
ng

7 Maxi
mum andMi
nimum of


N’number
s

8 Ascendi
ngOr
der

9 Mat
ri
xMani
pul
ati
on

10 NCRandNPR
2

S.
NO DATE NAMEOFTHEPROGRAM PAGE STAFF
NO SI
GNATURE

11 Gr
adeofst
udent
susi
ngI
f-

El
seLadder

12 St
ri
ngHandl
ingFunct
ion

13 I
ntegerFi
le

14 Quadr
ati
cEquat
ion

15 Fact
ori
alusi
ngRecur
sion

16 St
udentmar
kli
stusi
ng

ar
rayofst
ruct
ures

17 St
udentMar
kli
stusi
ng

Fi
le

18 PayBi
llusi
ngFi
le

19 I
nvent
orycont
rol

20 EBBi
llusi
ngFi
le
3

SUM OFDI
GITS

AI
M
Towr
it
eaCpr
ogr
am t
ofi
ndt
hesum ofdi
git
sofagi
vennumber
.

ALGORI
THM
1.Incl
udet
heappr
opri
ateheaderf
il
es,
star
tthemai
nfunct
ion
anddecl
aret
hevar
iabl
es.

2.Readt
hev
alueof‘
n’
.

3.I
nit
ial
izesum=0.

4.Usi
ngt
hewhi
lel
oopchecki
ngf
ort
hev
alueofn>0.

i
.m=n%10

i
i.sum=sum+m

i
ii
.n=n/
10

5.Pr
intt
hev
alueofsum.

6.Hal
tthepr
ogr
am.
4

SOURCECODE
#incl ude<stdio.h>
#incl ude<coni o.
h>
voidmai n(
)
{
i
ntm, n,
sum=0;
cl
rscr ()
;
printf (
"\t\t
\t**
* *
***
* *
****
\ n")
;
printf (
"\t\t
\tSUM OFDI GITS\n")
;
printf (
"\t\t
\t**
* *
***
* *
****
\ n")
;
printf (
"Enterthenumber :
\ t"
);
scanf ("
%d" ,
&n);
whi le(n>0)
{
m=n%10;
sum=sum+m;
n=n/ 10;
}
printf (
"\nSUM=%d" ,sum);
get ch( )
;
}
5

OUTPUT
6

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

ARMSTRONGNUMBER

AI
M
Towri
teaCprogram t
ocheckwhet
heragi
vennumberi
s
anArmst
rongnumberornot.
ALGORI
THM
1.I
ncl
udetheappr
opri
ateheaderf
il
es,
star
tthemai
n
f
unct
ionanddecl
arethevar
iabl
e.
2.Readt
hev
alueofn.
3.I
nit
ial
izesum=0andst
oreni
nt.
4.Usi
ngt
he“
whi
le”l
oopchecki
ngf
ort
hev
alueofn>0.
i
. s=n%10
i
i. sum=sum+s*
s*s
i
ii
. n=n
5.Ifsum==tt
henpr
intt
hegivennumberi
san
Armstr
ongnumberother
wise,
notanArmst
rong
number.
6.Hal
tthepr
ogr
am.
7

SOURCECODE
#incl ude<stdio.h>
#incl ude<coni o.
h>
voidmai n(
)
{
i
ntn, t,
sum=0, s;
clrscr (
);
printf (
"\n\t\
t\t***
****
****
*****\
n")
;
printf (
"\t\t
\tARMSTRONGNUMBER\ n"
);
printf (
"\t\t
\t**
* *
****
****
****\
n");
printf (
"Enterthenumber :
\t"
);
scanf (
"%d" ,
&n);
t=n;
whi le(n>0)
{
s=n%10;
sum=sum+s* s*s;
n=n/ 10;}
i
f(sum==t )
printf (
"\nThegi vennumber i
sanar mstr
ongnumber
");
else
printf (
"\nThegi vennumberi snotanarmstr
ongnumber"
);
get ch();
8

OUTPUT
9

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

PRI
MENUMBER

AI
M
Towri
teaCpr
ogr
am t
ocheckwhet
heragi
vennumberi
s
pr
imeornot
.

ALGORI
THM
1.I
ncl
udet
heappr
opr
iat
eheaderf
il
es,
star
tthemai
n

f
unct
ionanddecl
aret
hev
ari
abl
es.
10

2.Acceptt
henumberf
orm user(
n).

3.I
nit
ial
izet
heIv
alues(
i=1)
.

4.I
fiv
aluei
slesst
henn,
got
ost
ep5ot
her
wisegot
o
st
ep8.

5.cal
cul
ateqv
alues(
n%1)
.

6.I
fqv
aluei
szer
othengot
ost
ep7ot
her
wisegot
ost
ep4.

7.I
ncr
ementsv
aluegot
ost
ep4.

8.I
fthesv
aluei
slessthenonequalt
othegi
vennumber
i
sprimeot
herwi
sestep9.

9.Di
spl
ayt
hegi
vennumberi
snotpr
ime.

10.Hal
tthepr
ogr
am.
11

SOURCECODE
#incl ude<stdio.h>
#incl ude<coni o.
h>
voidmai n(
)
{
i
nti ,n,s,
q;
clrscr (
);
printf("\n\t\
t\t***
****
****
*\n")
;
printf("\t\t
\tPRIMENUMBER\ n")
;
printf("\t\t
\t**
* *
****
****
\n")
;
printf("Enteranumber :\
n");
scanf (
"%d" ,
&n);
s=0;
for(i=2;i<n;i
++)
{
q=n%i ;
i
f(q==0)
s=s+1;
}
i
f(s<=1)
printf("Thegi vennumberisapr i
menumber
");
else
printf("Thegi vennumberisnotapri
menumber "
);
get ch();
}
12

OUTPUT
13

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

FI
BONACCISERI
ES

AI
M

Towr
it
eaCpr
ogr
am t
ogener
atet
heFi
bonacci
ser
ies.
ALGORI
THM
1.I
ncl
udetheappr
opri
ateheaderf
il
es,st
artt
hemai
n
f
unct
ionanddecl
arethevar
iabl
es.

2.Readt
hev
alueofn.

3.I
nit
ial
izea=0andb=1.

4.Usi
ngthe‘f
or’
loopf
orexact
ingnt
imet
odot
he
fol
lowi
ng.

a)c=a+b

b)pr
intc

c)a=b

d)b=c

5.Hal
tthepr
ogr
am.
14

SOURCECODE
#incl ude<st dio.h>
#incl ude<coni o.h>
voidmai n()
{
i
nta, b,c,i,n;
clr
scr (
);
a=0;
b=1;
printf(“\n\ t\
t\t*****
* *
*****
****\n”);
printf(“\t\t\tFIBONACCISERI ES\ n”)
;
printf(“\t\t\t******
*******
******
\ n”)
;
printf("Ent erthenumber ")
;
scanf (
"%d" ,&n);
printf("\nThef i
bonacciseries\n");
printf(\n%d\ n%d” ,
a,b);
for(i=1;i<=n;i++)
{
c=a+b;
printf("%d\ n",c);
a=b;
b=c;
}
get ch();
}
15

OUTPUT
16

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

ADAM NUMBER

AI
M
Towrit
eaCpr
ogr
am t
odi
spl
ayt
hegi
vennumberi
sAdam
numberornot.

ALGORI
THM
1. I
ncl
udetheappr
opri
ateheaderf
il
es,st
artt
hemai
n
f
unct
ionanddecl
arethevar
iabl
es.

2. Readt
hev
alueofnum

3. I
nit
ial
izer
ev1=0andr
ev2=0

4. Fi
ndt
hesquar
eofnumber
sandst
orei
nsq

5. Usi
ngt
hewhi
lel
oopchecki
ngf
ort
hev
alueofsq>0

R1=sq%10;

Rev
=rev
*10+r
1;

Sq=sq/
10;
17

6. Fi
ndt
hesquar
erootofr
evandst
orei
nr2

7. Usi
ngt
he“
whi
le”l
oopchecki
ngf
ort
hev
alueof

n>0

r
3=r
2%10;

r
ev2=r
ev2*
10+r
3;

r
2=r
2/10;

8. I
frev2==num t
henpr
intt
hegi
vennumberi
sanadam numberor
not

9. Hal
tthepr
ogr
am.

SOURCECODE
#include<stdi o.h>
#include<coni o.h>
#include<mat h.h>
voidmai n()
{
i
ntnum, sq,r
1,r 2,
r3,rev1,
rev2;
cl
rscr (
);
printf
(“\n\t\
t\t *****
* *
****\
n”);
printf
(“\t\t
\tADAM NUMBER\ n”)
;
printf
(“\t\t
\t*** *
* *
*****”
);
whi l
e(sq>0)
printf
("\nEnt ert henumber ")
;
scanf (
"%d" ,
&num) ;
sq=pow( num, 2);
18

r
ev1=0;

{
r1=sq%10;
rev1=r ev1*10+r1;
sq=sq/ 10;
}
r2=sqr t(rev
1);
rev2=0;
whi le(r
2>0)
{
r3=r 2%10;
rev2=r ev2*10+r3;
r2=r 2/10;
}
i
f(rev 2==num)
printf("\nThegivennumberi
sanadam number"
);
else
printf("\nThegivennumberi
snotanadam number"
);
get ch();
}

OUTPUT
19

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.
20

REVERSI
NGANUMBERANDSTRI
NG

AI
M

Towr
it
eaCpr
ogr
am t
opr
intr
ever
seoft
hegi
vennumberand
st
ri
ng.

ALGORI
THM
1.I
ncludet
heappropri
ateheaderf
il
es,st
artt
hemai
nfunct
ionand
decl
aret
hevar
iable.

2.I
nswitchcaseusecase1,t
orev
erset
hegi
vennumberusi
ng
whi
lel
oop.

3.I
nswi
tchcaseusecase2,
tor
ever
set
hegi
venst
ri
ng.

4.I
nswi
tchcaseusecase3,
toexi
tfr
om t
heswi
tch.

5.Di
spl
ayt
her
esul
ts.

6.Hal
tthepr
ogr
am.
21

SOURCECODE
#include<st dio.h>
#include<coni o.h>
#include<st ring.h>
voidmai n()
{
i
ntn, r,
rev ,
ch,i,
len;
charst r[10],t
emp;
clr
scr ()
;
do
{
printf(
"\n1.Rev ersethegivennumber"
);
printf(
"\n2.Rev ersethestri
ng")
;
printf(
"\n3.Exi t");
printf(
"\nEnt ery ourchoice:"
);
scanf ("
%d" ,&ch) ;
swi t
ch(ch)
{
case1:
printf(
"Ent eranynumber :"
);
scanf ("
%d" ,&n) ;
rev=0;
whi l
e(n)
{
r=n%10;
rev=r ev*10+r ;
n=n/ 10;
}
printf(
"Rev ersenumberi s:%d",
rev
);
break;
case2:
printf(
"Ent erst r
ingtoreverse;
")
;
scanf ("
%s" ,str);
l
en=st rlen(str)-1;
for(i
=0;i<st rl
en( str
)/2;
i
++)
22

{
temp=st r[
i];
str[
i]=str
[l
en];
str[
len--]
=temp;
}
pri
nt f(
"%s",st
r);
break;
case3:
exit
() ;
}
}
while(ch<=3);
getch( )
;
}
23

OUTPUT
24

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

MAXI
MUM ANDMI
NIMUM OF‘
N’NUMBERS

AI
M
Towri
teaCprogr
am t
ofi
ndmi
nimum andmaxi
mum ofn
number
susi
ngarr
ay.

ALGORI
THM

1.
Incl
udet
heappr
opr
iat
eheaderf
il
es,
star
tthemai
n
f
unct
ionanddecl
aret
hev
ari
abl
es.

2.
Readt
heel
ementi
nar
ray
.

3.
Let
’ he1st el
ssupposet ementofasmaxi
mum setmax
=ar
ray
[10]
.

4.
Seti
=0.

5.
Ifar
ray[
i]
>maxt
hensetmax=ar
ray
[i]
.

6.
Incr
ementIbyseti
=i+1.

7.
Respectst
ep4-
5ti
lli
<si
ze(
wher
ethesi
zeofar
ray
).
25

SOURCECODE
#include<st dio.h>
#include<coni o.h>
voidmai n(
)
{
i
ntar r[
100] ;
i
nti ,
max, mi n,size;
clr
scr (
);
print
f("\n\t\t\t*******
****
*****
***\n")
;
print
f("\t\t
\ tMINI MUM ANDMAXI MUM\n");
print
f("\t\t
\ t*
* ******
****
*****
**\n");
print
f("Entert hesi zeofarray:
\t"
);
scanf (
"%d" ,&size);
print
f("Entert heel ementinthear r
ay\n"
);
for(i
=0;i<size;i++)
{
scanf (
"%d" ,&arr[i]
);
}
max=ar r[
0];
min=ar r[0]
;
for(i
=1;i<size;i++)
{
i
f(arr[
i]
>max)
{
max=ar r[
i]
;
}
i
f(arr[
i]
<mi n)
{
26

min=arr[
i]
;
}
}
pri
ntf(
"Maximum Element
=%d\t"
,max);
pri
ntf(
"Minimum El
ement=%d\
t",
min);
getch(
);
}

OUTPUT
27

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

ASCENDI
NGORDER

AI
M
Towri
teaCpr
ogr
am t
oar
ranget
hegi
vennumberi
nascendi
ng
or
der

ALGORI
THM
1.I
ncl
udetheappr
opri
ateheaderf
il
es,st
artt
hemai
n
f
unct
ionanddecl
arethevar
iabl
es.

2.Gett
henumberofel
ement
stosor
t.

3.Gett
henumber
stosor
tusi
ngf
orl
oop.

4.Swapt
henumber
susi
ngi
f(
a[i
]>a[
j]
)

5.Pr
intt
her
esul
ti
ngar
ray
.

6.Hal
tthepr
ogr
am.
28

SOURCECODE
#include<st dio.h>
#include<coni o.
h>
voidmai n()
{
i
nta[ 10],i,
j
,n,temp;
clrscr(
);
printf
("\n\t\t\t***
****
****
****
\n")
;
printf
("\t\t\tASCENDI NGORDER\ n")
;
printf
("\t\t\t****
****
****
***\
n");
printf
("Ent erthenumberofel ements:\
t")
;
scanf (
"%d" ,&n);
printf
("Ent erthenumber stosort
:\n"
);
for(i
=0;i<n;i++)
scanf (
"%d" ,&a[i]
);
for(i
=0;i<n;i++)
{
for(j
=i+1;j<n;j++)
{
i
f (
a[i]
>a[j])
{
temp=a[ i];
a[i
]=a[j]
;
a[j
]=temp;
29

}
}
}
pri
ntf("
\nTheascendi
ngor
deroft
hegi
vennumber
sar
e:\
n")
;
for
(i=0;
i<n;
i++)
pri
ntf("
\n%d",a[
i]
);
getch()
;
}

OUTPUT
30

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

MATRI
XMANI
PULATI
ON

AI
M
Towr
it
eacpr
ogr
am t
oadd,
subt
ractandmul
ti
plyt
womat
ri
ces.

ALGORI
THM
1.I
ncludet
heappropri
ateheaderf
il
es,st
artt
hemai
nfunct
ionand
decl
aret
hevar
iable.

2.Gett
heel
ement
sofmat
ri
xAandBusi
ngf
orl
oop.
3.Addandsubt
ractt
hemat
ri
cesAandB
4.Mul
ti
plyt
hemat
ri
cesAandB
5.Di
spl
ayt
her
esul
tantmat
ri
ces.
6.Hal
tthepr
ogr
am.
31

SOURCECODE
#include<st dio.h>
#include<coni o.h>
voidmai n()
{
i
nta[ 3][
3] ,
b[3][3],
sum[3][
3],
sub[3][
3],
mul[
3][
3],
i,
j
,k;
clr
scr (
);
print
f("\n\t\t\t
* **
*****
*****
******\
n");
print
f("\t\t
\tMATRI XMANI PULATI ON\n"
);
print
f("\t\t
\t*** *
*****
*****
*****
\ n"
);
print
f("\nEnt ertheelementsofmat r
ixA:
\n")
;
for(i
=0;i
<3; i
++)
{
for(j
=0;j
<3; j
++)
{
scanf (
"%d" ,
&a[ i]
[j
])
;
}
}
print
f("\nEnt ertheelementsofmat r
ixB:
\n"
);
for(i
=0;i
<3; i
++)
{
for(j
=0;j
<3; j
++)
{
32

scanf(
"%d" ,
&b[ i
][
j]
);
}
}
for
(i
=0;i<3;
i++)
{
for
(j
=0;j<3;
j++)
{
sum[i]
[j
]=a[i
][j]
+b[i]
[j
];
sub[i
][
j]
=a[i]
[j]-
b[i]
[j
];
}
}
for
(i
=0;i<3;
i++)
{
for
(j
=0;j<3;
j++)
{
mul[i
][
j]
=0;
for
(k=0;k<3;k++)
{
mul[i
][
j]
+=a[i][k]*
b[k][
j]
;
}
pri
ntf
("\n")
;
}
}
pri
ntf
("\nMat rixadditi
on\n")
;
for
(i
=0;i<3;
i++)
{
for
(j
=0;j<3;
j++)
{
pri
ntf
("%d\ t
",sum[ i
][
j]
);
}
pri
ntf
("\n")
;
}
pri
ntf
("\nMat rixsubtract
ion\n"
);
for
(i
=0;i<3;
i++)
{
for
(j
=0;j<3;
j++)
{
pri
ntf
("%d\ t
",sub[i]
[j
])
;
}
pri
ntf
("\n")
;
33

}
pri
ntf("
\nMatri
xMulti
pli
cat
ion\
n")
;
for
(i=0;
i<3;
i++)
{
for
(j=0;
j<3;
j++)
{
pri
ntf("
%d\t",
mul[
i]
[j
])
;
}
pri
ntf("
\n")
;
}
getch()
;
}

OUTPUT
34

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

NCRANDNPR
35

AI
M
Towr
it
eaCpr
ogr
am t
ocal
cul
ateNCRandNPR.

ALGORI
THM
1.I
ncludet
heappropri
ateheaderf
il
es,st
artt
hemai
nfunct
ionand
decl
aret
hevar
iable.

2.Cal
cul
atenprusi
ngt
hef
unct
ionf
act
(n)

3.Cal
cul
atencrusi
ngnpr

4.Pr
intt
hev
aluesofncrandnpr

5.Hal
tthepr
ogr
am.
36

SOURCECODE
#incl ude<st dio. h>
#incl ude<coni o.h>
l
ongi ntf act (
int) ;
voidmai n()
{
i
ntn, r;
l
ongi ntncr ,
npr ;
clr
scr (
);
printf("Ent erthev al
ueofn:"
);
scanf (
"%d" ,&n);
printf("Ent erthev al
ueofr:
")
;
scanf (
"%d" ,&r);
npr =fact (n)/fact (
n-r
);
ncr=npr /fact(r);
printf("NPRv alue=%d\n"
,npr)
;
printf("NCRv alue=%d\n"
,ncr)
;
get ch();
}
l
ongi ntf act (
intx)
{
i
nti ,f=1;
for(i=2;i<=x;i++)
{
f=f* i
;
}
returnf ;
}
37

OUTPUT
38

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

GRADEOFASTUDENTUSI
NGELSEI
FLADDER

AI
M
Towr
it
eaCpr
ogr
am t
odi
spl
aygr
adeofast
udentusi
ngel
sei
f
l
adder
.

ALGORI
THM

1.I
ncludet heappr opr
iateheaderfil
es,st
artthemain
functionanddecl ar
ethev ari
ables.
2.Entermar ksof5subj ects.
3.Calculatetotalmar ksusingt =s1+s2+s3+s4+s5
4.Calculateaver ageusingp=t /5
5.Calculategradeusi ngelseif.
6.Displayther esult.
7.Haltthepr ogram.
39

SOURCECODE
#include<stdi o.h>
#include<coni o. h>
voidmai n(
)
{
i
nts1, s2,s3,s4,s5, t
,p;
clr
scr (
);
printf
("\n\t\
t \t
** ***\n");
printf
("\t\t
\tGRADE\ n");
printf
("\t\t
\t**** *\n");
printf
("\nEnt ermar ksof5subj ect
seachoutof100"
);
printf
("\n\n*** ***********
*")
;
printf
("\n\nMat hs=" );
scanf (
"%d" ,
&s1) ;
printf
("\nSci ence=" ) ;
scanf (
"%d" ,
&s2) ;
printf
("\nEngl ish=" );
scanf (
"%d" ,
&s3) ;
printf
("\nHi story =");
scanf (
"%d" ,
&s4) ;
printf
("\nGeogr aphy ="
);
scanf (
"%d" ,
&s5) ;
printf
("\n\n*** ***********
****"
);
t=s1+s2+s3+s4+s5;
printf
("\nTot alMar ks=%d" ,
t)
;
p=t /
5;
printf
("\n\nPer cent age=%d%",p);
printf
("\n\n*** ***********
****"
);
i
f(p>=80)
printf
("\n\nYourgr ade:A+")
;
40

el
sei f
(p>=75)
pri
ntf(
"\n\nYourgr
ade:A")
;
el
sei f
(p>=60)
pri
ntf(
"\n\nYourgr
ade:B")
;
el
sei f
(p>=45)
pri
ntf(
"\n\nYourgr
ade:C")
;
el
sei f
(p>=35)
pri
ntf(
"\n\nYourgr
ade:D")
;
el
se
pri
ntf(
"\n\nYouarefai
l"
);
getch()
;
}
41

OUTPUT
42

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

STRI
NGHANDLI
NGFUNCTI
ONS

AI
M
Towrit
eaCpr
ogr
am t
oimpl
ementt
hev
ari
ousst
ri
nghandl
ing
f
unct
ions.

ALGORI
THM
1.I
ncludet
heappropr
iat
eheaderf
il
es,st
artt
hemai
nfunct
ionand
decl
aret
hevar
iabl
e.

2.Ent
ert
hev
aluesofst
ri
ngs

3.Fi
ndt
hel
engt
hofst
ri
ngsanddi
spl
ayt
hem

4.Combi
net
wost
ri
ngsandf
indt
hel
engt
h

5.Pr
intt
hecombi
nedst
ri
ngandi
tsl
engt
h

6.Hal
tthepr
ogr
am
43

SOURCECODE
#include<stdio.h>
#include<conio.h>
#include<stri
ng. h>
voidmai n()
{
chars1[ 20],
s2[20],s3[
20]
;
i
ntl 1,
l2,
l3,x;
cl
rscr (
);
printf
("\
t\t\t
***** *
****
***
***
***
***
***
\n"
);
printf
("\
t\t\t
STRI NGHANDLI NGFUNCTIONS\
n")
;
printf
("\
t\t\t
***** *
****
***
***
***
***
***
\n"
);
44

pri
nt f
("Entertwost ri
ngs:
");
scanf("\n%s" ,
s1);
scanf("\n%s" ,
s2);
x=strcmp( s1,s2);
i
f(x!=0)
pri
nt f
("Stri
ngar enotequal")
;
el
se
pri
nt f
("Equalstrings")
;
pri
nt f
("\n");
l
1=st rl
en(s1);
l
2=st rl
en(s2);
pri
nt f
("Lengthof%s=%d" ,s1,l
1);
pri
nt f
("\nLengthof%s=%d" ,s2,
l2);
strcat(
s1,s2);
strcpy(s3,s1);
l
3=st rl
en(s3);
pri
nt f
("\ns3=%s\ nLengt
h=%d" ,
s3,l
3);
getch();
}

OUTPUT
45

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

I
NTEGERFI
LE
46

AI
M
Towrit
eaCprogr
am t
ocr
eat
eani
ntegerf
il
eanddi
spl
ayi
ngt
he
ev
ennumber
sonl
y.

ALGORI
THM

1.Includet heappr opri


ateheaderf il
es,star
tthemain
functionanddecl arethev ar
iables.
2.Opent hefile“ DATA”i n“ w”modeandent ernumber
checki tisev enornot .
3.Closet hef il
ef 1.
4.Agai nopent hef il
ef1i n“r”modef orreadingtherecor
d.
5.Checkt henumberwhet herthenumberi sevenstatthe
numberi nt heev enf i
leelseprintthenumberi snot
even.
6.Closebot ht hef i
le.
7.Opent he“EVEN”f i
lein“r”mode.
8.Printther esul t.
9.Hal tthepr ogr am.
47

SOURCECODE
#incl ude<st dio.h>
#incl ude<coni o.h>
voidmai n()
{
FILE* f1,*f
2;
i
ntnumber ,i
;
clrscr ()
;
printf("Cont entsofDATAf i
le\
n\n")
;
f1=f open( "DATA" ,"
w" )
;
for(i=1;i<=5;i++)
{
scanf ("
%d" ,
&number );
i
f(number ==1)
break;
put w( number ,
f1);
}
fclose( f1);
f1=f open( "DATA" ,"
r")
;
f2=f open( "EVEN" ,"
w");
whi le((number =getw(f1)
)!
=EOF)
{
i
f(number %2==0)
put w( number ,
f2);
}
fclose( f1);
fclose( f2);
f2=f open( "EVEN" ,"
r")
;
printf("\n\nCont entsofEvenfi
le\
n\n"
);
whi le((number =getw(f2)
)!
=EOF)
printf("%4d" ,number );
fclose( f2);
get ch( )
;
}
48

OUTPUT

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.
49

QUADRATI
CEQUATI
ON

AI
M
Towr i
teaCpr
ogr
am t
ocal
cul
atequadr
ati
cequat
ionusi
ng
swi
tchcase.

ALGORI
THM
1.I
ncl
udetheappr
opri
ateheaderf
il
es,st
artt
hemai
n
f
unct
ionanddecl
arethevar
iabl
es.

2.Acceptt
hei
nputv
alues(
a,b,
c).

3.Fi
nddv
alue(
b*b-
4*a*
c).

4.Fi
ndd=0t
hengoy
ost
ep5ot
herwi
segot
ost
ep6.

5.Fi
ndt
her
oot
s(r
1,r
2)andgot
ost
ep9(
r1=-
b/(
2*a)
,r
2=r
1) .

6.I
fD>0t
hengot
ost
ep7ot
her
wisegot
ost
ep3.

7.Fi
ndt
her
oot
s(r
1,r
2)andgot
ost
op

r
1=b-
b+sqr
t(d)
/(2*
0)

R2=-
b-sqr
t(d)
/(2*
0)]

8.Fi
ndt
her
oot
s(r
1,r
2)got
ost
ep9.

9.Hal
tthepr
ogr
am.
50

SOURCECODE

#include<st dio.h>
#include<coni o.h>
#include<mat h.h>
voidmai n( )
{
i
nta, b,c;
fl
oatd, r1, r
2;
clrscr(
) ;
printf(
"\n\ t\t\t***
** *****
********\n"
);
printf(
"\t\ t
\tQuadr at i
cequat ion\n");
printf(
"\t\ t
\t*** *
**** **
********\n")
;
printf(
"Ent ert hev aluesofa, b,c\n")
;
scanf (
" %d\ t%d\ t%d" ,
&a,&b,&c);
i
f((a!=0) &&( b!=0)&&( c!=0))
{
d=b* b-(4* a*c);
i
f( d>0)
{
r1=(-b+sqr t
(d) )/
(2* a);
r2=(-b-sqr t(
d) )/(
2* a);
printf(
"root 1=%f \nr oot2=%f",
r1,r2);
printf(
"\nRoot sar er ealandunequal \
n");
}
elseif(d==0)
{
r1=-b/(2. 0*a);
r2=r1;
printf(
"root 1=%f \nr oot2=%f",
r1,r2);
printf(
"\nTher ootsar erealandequal "
);
}
elseif(d<0)
{
r1=-b/(2* a);
r2=sqr t(abs( d))/(
2* a);
51

pri
ntf(
"root
1=%f\nroot2=%f"
,r
1,r
2);
pri
ntf(
"\nTher
oot sareimaginar
y")
;
}
}
el
se
{
pri
ntf(
"I
tisnotpossible")
;
}
getch(
);
}
52

OUTPUT
53
54

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

FACTORI
ALUSI
NGRECURSI
ON

AI
M
TowriteaCprogram t
ocal
cul
atef
act
ori
alofagi
vennumber
usi
ngrecur
sivef
uncti
on.

ALGORI
THM
1.I
ncl
udetheappr
opri
ateheaderf
il
es,st
artt
hemai
n
f
unct
ionanddecl
arethevar
iabl
es.

2.Readt
hev
alueofn

3.Cal
lthef
unct
ionf
act
(n)

4.I
nthef
unct
ionf
actt
ocal
cul
atef
act
ori
alv
alue.

5.Di
spl
ayt
her
esul
t.

6.Hal
tthepr
ogr
am.
55

SOURCECODE
#include<stdio. h>
#include<coni o.h>
voidmai n(
)
{
i
ntn;
l
ongi ntfactori
al (
int
);
clr
scr ()
;
printf("
\t\t
\t**
* *****
*****
******
***
***
\n"
);
printf("
\t\t
\tFACTORI ALUSINGRECURSION\
n")
;
printf("
\t\t
\t**
* *****
*****
******
***
***
\n"
);
printf("
Enterthenumber :
\t")
;
scanf ("
%d" ,
&n);
printf("
\nThef actori
alofthenumber%d=%d",
n,
fact
ori
al(
n))
;
get ch()
;
}
l
ongi ntfactori
al( i
ntn)
{
i
f( n<=1)
return(1);
56

else
retur
n(n*f
act
ori
al(
n-1)
);
}

OUTPUT
57

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

STUDENTMARKSTATEMENTUSI
NGARRAYOF
STRUCTURES

AI
M
Towr i
teaCpr
ogr
am t
ogener
atest
udentmar
kli
stusi
ngar
ray
ofst
ruct
ures.

ALGORI
THM
1.I
ncl
udetheappr
opri
ateheaderf
il
es,st
artt
hemai
n
f
unct
ionanddecl
arethevar
iabl
es.

2.Cr
eat
east
ruct
uret
hathol
dst
hest
ruct
urev
ari
abl
e.

3.Uset
hedotoper
atort
oref
ert
hest
ruct
urev
ari
abl
e.
58

4.Dot
hecal
cul
ati
onssuchast
otal
,av
erage

5.Pr
intt
her
esul
t.

6.Hal
tthepr
ogr
am.

SOURCECODE
#include<stdio.
h>
#include<conio.h>
voidmai n()
{
structstudent
{
charname[ 10] ;
i
ntmar ks[
6],t
otal;
fl
oatav g;
}s;
i
nti ;
clr
scr (
);
s.t
ot al
=0;
59

printf("
Enterthest udentname: ");
scanf ("%s",
s.name) ;
printf("
\nEnt er6mar ks\n");
for(i=0;i
<6;i
++)
{
scanf ("%d",
&s. marks[i]
);
s.total=s.t
otal+s.mar ks[
i]
;
s.av g=s.t
otal/6;
}
printf("
\n\t\tStudentI nf
or mati
on\ n");
printf("
\n~~~~~~~~~* *******
* ***
******
***
***
***
***
***
*~~~~~~~~~
\n");
printf("
\nSt udentName: %s",s.
name) ;
printf("
\nMar ks:
");
for(i=0;i
<6;i
++)
{
printf("
%d\ t",
s.mar ks[i
])
;
}
printf("
\nTot alMar ks:%d",s.
total)
;
printf("
\nAv erageMar ks:%5.2f\n",
s.avg)
;
printf("
\n~~~~~~~~~* *******
* ***
******
***
***
***
***
***
*~~~~~~~~~
");
get ch();
}

OUTPUT
60

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

STUDENTMARKLI
STUSI
NGFI
LE

AI
M
61

Towr i
teaCpr
ogr
am t
ocr
eat
eandpr
ocessst
udentmar
kli
st
usi
ngfi
le.

ALGORI
THM
1.I
ncludet heappr opri
ateheaderfil
es,st
artt
hemai n
functionanddecl arethev ar
iabl
es.
2.Opent hef
ile“Mar k.
dat”in“w”modeandent erthe
detai
lsofst udent.
3.Closet hefil
ef 1.
4.Againopent hefil
ef1i n“r”mode.
5.Calculatetotalandav eragemarksofthestudent.
6.Displayther esul
ts.
7.Closet hefil
ef 1.
8.Halttheprogr am.

SOURCECODE
#i
ncl
ude<stdi
o.h>
#i
ncl
ude<coni
o.h>
62

voidmai n()
{
FILE* f1;
charname[ 10];
i
nti ,tam, eng, mat,tot;
fl
oatav g;
clrscr ()
;
f1=f open( "
mar k.dat ",
"w")
;
printf("NameTami lEngli
shMat \n");
for(i=0;i<5;i++)
{
fscanf (
st din,"
%s%d%d%d" ,
name, &tam,&eng,&mat)
;
fprintf(f1,"%s%d%d%d" ,
name, tam, eng,mat);
}
fclose( f1) ;
f1=f open( "
mar k.dat ",
"r
");
printf("\n\ t
\ t
******* *
********
* ****
* *****\
n")
;
printf("\t\t\tStudentRecor d\n");
printf("Name Tami l Engl ish Mat hs Tot al Av
erage\
n")
;
for(i=0;i<5;i++)
{
fscanf (
f1,"%s%d%d%d" ,
name, &tam, &eng,
&mat )
;
tot=t am+eng+mat ;
avg=t ot/3.0;
fprintf(stdout ,"
%-12s%- 10d%- 10d%- 10d%-10d%-
10f \n" ,
name, t
am, eng,mat ,
tot,avg);
}
fclose( f1) ;
get ch( )
;
}

OUTPUT
63

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

PAYBI
LLUSI
NGFI
LE
64

AI
M
Towr
it
eaCpr
ogr
am t
ocr
eat
eandpr
ocesspaybi
llusi
ngf
il
e.

ALGORI
THM

1.Incl
udet heappr opri
ateheaderfi
les,
star
tthemainfunct i
on
anddecl arethev ar
iabl
es.
2.Opent hef il
e“EMP.DAT”i n“w”modeandent erdet
ail
sf orn
employ ers.
3.Closethef i
l
e.
4.Openagai nthesamef il
esin“r”modeforreadi
ngtherecor ds.
5.Readt her ecordsonebyoneandsentout puttothestandar d
output.
6.Closethef i
l
e.
7.Haltthepr ogram

SOURCECODE
#i
ncl
ude<stdi
o.h>
#i
ncl
ude<coni
o.h>
65

voidmai n()
{
FILE* fptr;
charname[ 50];
i
ntn, n1,age, bs;
clrscr ()
;
printf("\n\ t
\ t
\t***
******
* **
******
* *
*\n")
;
printf("\t\t\tPAYBI LLCALCULATI ONS\ n");
printf("\t\t\t****
*****
**********
**\n");
fptr=f open( "EMP. DAT",
"w" )
;
printf("Ent erthev al
uef orn\n");
scanf ("
%d" ,&n);
n1=n;
printf("Ent ertheempname, age,basicsalary\n")
;
whi le(n>0)
{
fscanf (
st din,"
%s%d%d" ,name,&age,&bs);
fprintf(fpt r
,"%s%d%d" ,
name, age,bs);
n=n- 1;
}
fclose( fpt r
);
fptr=f open( "EMP. DAT",
"r")
;
printf("\nCont entsoffileare:
\n\t")
;
printf("\nNAME AGE BASI CSALARY\ n\t"
);
fprintf(stdout ,"
\n\n")
;
whi le(n1>0)
{
fscanf (
fpt r,
"%s%d%d" ,
name, &age,&bs);
fprintf(stdout ,"
%-10s%- 2d%- 8d\n",
name, age,bs);
n1- -
;
}
fclose( fpt r
);
get ch( )
;
}

OUTPUT
66

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

I
NVENTORYCONTROL
67

AI
M
Towri
teaCpr
ogr
am Tocr
eat
eandpr
ocessi
nvent
orycont
rol
usi
ngst
ruct
ure.

ALGORI
THM

1.I
ncl
udetheheaderf
il
esandst
artt
hemai
nf uncti
on.
2.Def
inest
ruct
urenamedasdat
aanddecl
areits
vari
abl es.
3.Definest ructur
enamedasdet ai
lsanddecl
arei
ts
vari
abl es.
4.Gett henumberofi tems
5.Getname,quant i
ty,
price,manuf
actur
ingdat
eofthe
product .
6.Displayt heinventor
ydet ai
ls.
7.Hal tthepr ogram.

SOURCECODE
68

#include<st dio.h>
#include<coni o.h>
voidmai n()
{
structdat e
{
i
ntday ;
i
ntmont h;
i
nty ear ;
};
structdet ails
{
charname[ 20];
i
ntpr ice,code,qt y;
structdat emf g;
};
structdet ailsitem[ 50];
i
ntn, i
;
clr
scr ();
printf
(“\n\t \
t\t**************
****\
n”)
;
printf
(“\t\t\tI
NVENTORYMANAGEMENT\ n”
);
printf
(“\t\t\t**
* **********
* *
*****
\n”)
;
printf
("Ent ernumberofi tem:")
;
scanf ("
%d" ,&n);
ffl
ush( stdin);
for(i
=0; i
<n;i++)
{
ffl
ush( stdin);
printf
("it
em name: ");
scanf ("
%[ ^\n]"
,item[i].
name) ;
ffl
ush( stdin);
printf
("It
em code: ");
scanf ("
%d" ,&it
em[ i
].code);
ffl
ush( stdin);
printf
("Quant i
ty:")
;
scanf ("
%d" ,&it
em[ i
].qty)
;
ffl
ush( stdin);
printf
("price:")
;
scanf ("
%d" ,&it
em[ i
].pri
ce);
ffl
ush( stdin);
69

pri
ntf("
Manuf acturingdat e(dd- mm- yy) :
")
;
scanf("%d%d%d" ,&item[i]
.mf g.day,&i
t em[ i]
.mfg.
mont h,&i
tem[ i
].mfg.ye
ar)
;
}
pri
ntf("
*****INVENTORY* *
* *
* \n");
pri
ntf("
---
--
----
---
---
---
----
--
--
--
----
---
----
--
--
--
-----
----
--
--
--
--
--
---
--
--
---
--
--
\ n")
;
pri
ntf("
s.no|Name |Code |Quant ity |Pr i
ce|MFG. Date\
n" )
;
pri
ntf("
---
--
----
---
---
---
----
--
--
--
----
---
----
--
--
--
-----
----
--
--
--
--
--
---
--
--
---
--
--
\ n")
;
for
(i=0;i
<n;i++)
pri
ntf("
%-4d%- 15s%- 2d%- 7d%- 8d
%d%d%d\ n" ,
i+1,i
tem[ i]
.name, item[i]
.code, i
tem[i]
.qt
y,i
tem[i].pr
ice,
item[i
]
.mfg.day,
item[ i
].mfg. mont h,
item[ i
].
mf g.year)
;
pri
ntf("
---
--
----
---
---
---
----
--
--
--
----
---
----
--
--
--
-----
----
--
--
--
--
--
---
--
--
---
--
-\n");
getch();
}

OUTPUT
70

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

EBBI
LLUSI
NGFI
LE
71

AI
M
Towri
teaCpr
ogr
am t
ocr
eat
eandpr
ocessEBbi
llcal
cul
ati
on
usi
ngst
ruct
ure.

ALGORI
THM

1.Incl
udet heappr opr
iateheaderfil
es,startthemain
functionanddecl ar
et hevari
ables.
2.Definest ruct urenamedasbi llanddecl ar
ei t
svari
abl
es.
3.Startintmai n()anddecl arei
tsvari
ables.
4.Gett hef i
rstname, lastname,previousunits,and
currentuni ts.
5.Callthef unct iongener at
ebil
l.
6.Calcul at
eamountt opayandr eturnittomai n()
.
7.Displayt her esult.
8.Haltt hepr ogr am.

SOURCECODE
#i
ncl
ude<st
dio.
h>
72

#include<coni o.h>
structBi l
l
{
charf ir
stname[ 10];
charl astname[ 10];
charaddr ess[ 20];
fl
oatpr ev iousuni t
;
fl
oatpr esent uni t;
};
fl
oatgener ateBi l
l(st
ructBi lltemp)
{
fl
oatdi ff;
diff=temp. pr esent unit-temp. previousunit
;
i
f(di f
f>20)
{
return(diff*4. 75);
}
else
{
return( 20* 4.75+( diff
-20) *
7) ;
}
}
i
ntmai n()
{
structBi l
lbi ll
;
clrscr()
;
printf("
\n\ t\t\t********** *********
******
***\n"
);
printf("
\t\t\tELECTRI CI TYBI LLCALCULATI ON\n"
);
printf("
\t\t\t** ******
** *** *
** *
* *
*******
**\n")
;
printf("
\nFi llupt hef ollowi ng:\n\n")
;
printf("
FIRSTNAME: ");
get s(bi
ll.
firstname) ;
printf("
LASTNAME: ");
get s(bi
ll.
last name) ;
printf("
ADDRESS: ");
get s(bi
ll.
addr ess);
printf("
PREVI OUSUNI T:");
scanf ("
%f ",&bi l
l.
previousuni t);
printf("
PRESENTUNI T:");
scanf ("
%f ",&bi l
l.
present unit)
;
73

pri
ntf(
"\a\n\
n****
******
**** *Electr
ici
tybil
l*****
***
****
***
*\n\
n\a"
);
pri
ntf(
"NAME:%s%s" ,bill
.fi
rstname,bill
.l
astname);
pri
ntf(
"\nADDRESS:%s" ,bil
l.address)
;
pri
ntf(
"\nPREVIOUSUNI T:%. 3f\nCURRENTUNI T:
%.3f",
bil
l.
previ
ousunit
,bill
.presentuni
t);
pri
ntf(
"\nCOST:%. 3f
\n\n",generateBi
ll(
bil
l)
);
getch(
);
}

OUTPUT
74

RESULT
Thustheabovepr
gram hasbeenexecut
edsuccessf
ull
yandt
he
out
puti
sv er
if
ied.

You might also like