0% found this document useful (0 votes)
15 views

C - Record

The document provides an algorithm and coding for generating the Fibonacci series up to a given number of terms. It takes the number of terms as input, initializes the first two terms, then uses a for loop to calculate each subsequent term as the sum of the previous two and prints the series.

Uploaded by

MAADHESH
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)
15 views

C - Record

The document provides an algorithm and coding for generating the Fibonacci series up to a given number of terms. It takes the number of terms as input, initializes the first two terms, then uses a for loop to calculate each subsequent term as the sum of the previous two and prints the series.

Uploaded by

MAADHESH
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/ 38

EX.

NO:01
SUM,
AVERAGEANDSTANDARDDEVI
ATI
ON
DATE:

AI
M:

Towrit
eaCprogr
am t
ofi
ndt
hesum,
aver
ageandst
andar
ddev
iat
ionf
oragi
venset
ofnumber
s.

ALGORI
THM:

St
ep1:St
artt
hepr
ocess.

St
ep2:Gett
hev
aluesofar
raya[
]asi
nput
.

St
ep3:Cal
cul
atet
hesum usi
ngt
hef
ormul
asum=sum+a[
i]
.

St
ep4:Cal
cul
atet
heav
erageusi
ngt
hef
ormul
aav
erage=sum/
n.

St
ep5:Cal
cul
atet
hest
andar
ddev
iat
ionusi
ngt
hef
ormul
a

sd=sqr
t(si
/n-
(av
g*av
g))
.

St
ep6:Pr
intt
hev
aluesf
orSum,
Aver
ageandSt
andar
ddev
iat
ion.

St
ep7:St
opt
hepr
ocess.

1
CODI
NG:

/
*SUM,
AVERAGE&STANDARDDEVI
ATI
ON*
/

#include<st dio.h>
#include<coni o.h>
#include<mat h.h>
voidmai n()
{
i
nti ,n,a[50];
floatsi ,
av g=0. 0,sum=0.0,sd=0.0;
clrscr (
);
printf("\n\t\tSUM,AVERAGEANDSTANDARDDEVI ATI
ON"
);
pr i
ntf(
" \n\t\t* ******
*****
* **
******
*****
***
***
***
***
***
**"
);
pr i
ntf(
" \nEnt erthev al
uesofN: \t"
);
scanf ("%d" ,&n) ;
pr i
ntf(
" \n\nEnt ertheelement s:\
t")
;
for(i=0;i<n;i
++)
{
scanf ("%d" ,&a[ i
]);
sum=sum+a[ i]
;
si=si+(a[ i
]*a[i]);
}
av g=sum/ n;
sd=sqr t(
si/n-
(avg*avg));
pr i
ntf(
" \n\tsum=%0. 2f
\n",sum);
pr i
ntf(
" \n\tAv erage=%0.2f\n",
avg);
pr i
ntf(
" \n\tSt andar ddeviati
on=%0. 2f
",
sd)
;
get ch();
}

2
RESULT:

SUM,
AVERAGEANDSTANDARDDEVI
ATI
ON
*
***
***
***
***
***
***
***
***
***
***
***
***
***
***
Ent
ert
hev
aluesofN:
5

Ent
ert
heel
ement
s: 1
2
3
4
5
Sum=15.
00
Av
erage=3.
00
St
andar
ddev
iat
ion=1.
41

3
EX.
NO:02
PRI
MENUMBERS
DATE:

AI
M:

Towr
it
eaCpr
ogr
am t
ogener
ate‘
n’pr
imenumber
s.

ALGORI
THM:

St
ep1:St
artt
hepr
ocess.

St
ep2:Gett
hev
aluef
ori
nput
.

St
ep3:Openal
oopunt
ili
<=n+1.

St
ep4:Assi
gnxas0.

St
ep5:Openal
oopj
var
yingf
rom 2t
oi-
1.

St
ep6:Checkwhet
heri
%j==0,
thenx++.

St
ep7:Checkx==0,
pri
nti
&incr
ementi
.

St
ep8:El
secheckx>0t
henn++,
i
++.

St
ep9:Cl
oset
hel
oop.

St
ep10:St
opt
hepr
ocess.

CODI
NG:

#incl
ude<stdi
o.h>
#incl
ude<coni
o.h>
voidmain()
{
4
i
ntn,i=2,j,
x,
x1;
clr
scr();
pri
ntf("
\ n\t
\tGENERATE' N'PRIMENUMBER\ n"
);
pri
ntf("
\ n\t
\t*****
***
****
*****
****
***
***
*")
;
pri
ntf("
\ nEntertheli
mitofpri
menumber:");
scanf("%d",&n);
pri
ntf("
\ nThepr i
menumber sare:")
;
while(i<=n+1)
{
x=0;
for(j
=2; j
<i-
1;j
++)
{
i
f((i
%j)==0)
x++;
}
i
f(x==0)
{
pri
ntf("
\ n%d\t\
t",
i)
;
i
++;
}
i
f(x>0)
{
n++;
i
++;
}
}
getch();
}

RESULT:

GENERATE'
N'PRI
MENUMBER

*
***
***
***
***
***
***
***
***
***
*
5
Ent
ert
hel
i
mitofpr
imenumber:
9

Thepr
imenumber
sar
e:

11

13

17

19

23

EX.
NO:03
FI
BONACCISERI
ES
DATE:

AI
M:

6
Towr
it
eaCpr
ogr
am t
ogener
atet
heFi
bonacci
ser
ies.

ALGORI
THM:

St
ep1:St
artt
hepr
ocess.

St
ep2:Readt
henumber
soft
ermsi
ntheser
ies.

St
ep3:Assi
gnf
1=-
1&f
2=1.

St
ep4:Usi
ngf
orl
oopf
indt
heser
ies.

St
ep5:Cal
cul
atet
hef
3=f
1+f
2.

St
ep6:Assi
gnf
1asf
2andf
2asf
3.

St
ep7:Pr
intf
3andcont
inuet
hel
oopunt
ili
<=n.

St
ep8:St
opt
hepr
ocess.

CODI
NG:

#incl
ude<stdi
o.h>
#incl
ude<coni
o.h>
voidmain()
{

7
i
ntf 1,f
2,f3,
i,
n;
clr
scr (
);
f1=-1;
f2=1;
pri
nt f(
"\n\t
\tFIBONACCISERI ES");
pri
nt f(
"\n\t
\t******
*****
****
*");
pri
nt f(
"\nEnterthetotalnumber:
")
;
scanf (
"%d",&n);
pri
nt f(
"\nTheFi bonacciser
iesi
s:\n")
;
for(i=1;i
<=n;i
++)
{
f3=f1+f2;
f1=f2;
f2=f3;
pri
nt f(
"%d\n",
f3);
}
getch();
}

RESULT:

FI
BONACCISERI
ES

*
***
***
***
***
***
**

8
Ent
ert
het
otal
number
:10

TheFi
bonacci
ser
iesi
s:

13

21

34

EX.
NO:04
MAGI
CSQUARE
DATE:

AI
M:

9
Towr
it
eaCpr
ogr
am t
ofi
ndt
hemagi
csquar
eofor
deri
nwher
en>=3andni
sodd.

ALGORI
THM:

St
ep1:St
artt
hepr
ocess.

St
ep2:Read‘
n’v
alue.

St
ep3:Check‘
n’i
sev
ent
henpr
inter
rormessage.

St
ep4:El
secont
inuef
rom st
ep2.

St
ep5:Openal
oopi
var
yingf
rom 1t
on.

St
ep6:Openal
oopj
var
yingf
rom 1t
on.

St
ep7:Assi
gna[
i]
[j
]as0.

St
ep8:Cl
osei
&jl
oops.

St
ep9:Assi
gni
as0&j
=n/
2,a[
i]
[j
]as1.

St
ep10:Openal
oopkv
ary
ingf
rom 2t
on*
n.

St
ep11:Decr
ementi
&j.

St
ep12:Checki
<0t
hani
=n-
1.

St
ep13:Checkj
<0t
hanj
=n-
1.

St
ep14:Checka[
i]
[j
]!
=0t
hencal
cul
atei
=(1+2)
%n&j
=++j
%n.

St
ep15:El
seassi
gna[
i]
[j
]=kandcont
inuel
oop.

St
ep16:Openal
oopi
var
yingf
rom 0t
on-
1andj
var
yingf
rom 0t
on-
1.

St
ep17:Pr
inta[
i]
[j
].

St
ep18:Cl
oset
hel
oopsi
&j.

St
ep19:St
opt
hepr
ocess.

CODI NG:
#incl
ude<stdi
o.h>
#incl
ude<conio.h>
voidmai n(
)
{
i
nti,j
,k,
n,
a[10]
[10];
start
:

10
clr
scr (
);
pri
ntf (
"\n\t\
tMAGI CSQUARE" );
pri
ntf (
"\n\t\
t*****
*****
***
***")
;
pri
ntf (
"\nEnterthenumber :
");
scanf (
"%d" ,
&n);
i
f(n%2==0)
{
pri
ntf (
"\n\t\
tTypeonlyoddnumber")
;
pri
ntf (
"\n\t\
tMagicsquarecannotbepri
ntedforanyev
ennumber
");
getch();
gotost art;
}
for(
i=0;i<=n;
i++)
{
for(
j=0;j<=n;
j++)
a[i
][
j]=0;
}
i
=0;
j
=n/ 2;
a[i
][
j]=1;
for(
k=2; k<=n*n;
k++)
{
i
--;
j
--;
i
f(i
<0)
i
=n-1;
i
f(j
<0)
j
=n-1;
i
f(a[i
][j
]!
=0)
{
i
=(i+2)%n;
j
=++j %n;
}
a[i
][
j]=k;
}
pri
ntf (
"\n\tTheMagi cSquareof%di
s:\
n",
n);
for(i=0;i
<=n-1;i
++)
{
for(j=0;j
<=n-1;j
++)
pri
ntf (
"\t%5d",
a[i
][
j]
);
pri
ntf (
"\n\n")
;
}
getch();
}
RESULT:

MAGI
CSQUARE

*
***
***
***
***
**
11
Ent
ert
henumber
:5

TheMagi
cSquar
eof5i
s:

15 8 1 24 17

16 14 7 5 23

22 20 13 6 4

3 21 19 12 10

9 2 25 18 11

EX.
NO:05
SORTTHENUMBERSI
NASCENDI
NGORDER
DATE:

AI
M:

12
Towr
it
eaCpr
ogr
am t
osor
tthegi
vensetofnumber
sinascendi
ngor
der
.

ALGORI
THM:

St
ep1:St
artt
hepr
ocess.

St
ep2:Readt
he‘
n’v
alue.

St
ep3:Readt
hesetofv
aluesi
na[
i]byopeni
ngal
oopi
var
yingf
rom 0t
on.

St
ep4:Openal
oopi
var
yingf
rom 0t
on-
1.

St
ep5:Openal
oopi
var
yingf
rom i
ton.

St
ep6:Checkwhet
hera[
i]i
sgr
eat
ert
hana[
j]
.

St
ep7:I
fiti
str
ueswapt
hev
aluest
emp=a[
i]
,
a[i
]=a[
j]
,
a[j
]=t
emp.

St
ep8:El
secont
inuet
hel
oopj
&i.

St
ep9:Openal
oopi
var
yingf
rom 0-
n.

St
ep10:Pr
intt
hesetofv
aluesf
rom a[
i]i
nascendi
ngor
der
.

St
ep11:St
opt
hepr
ocess.

CODI
NG:

#incl
ude<stdi
o.h>
#incl
ude<coni
o.h>
voidmain()
{
13
i
nti ,
j
,n,a[50],
temp;
clr
scr (
);
pri
ntf("\n\t\tASCENDI NGORDER" );
pri
ntf("\n\t\t******
*****
*******
*");
pri
ntf("\nEnt erthenumberofi t
em:");
scanf (
"%d" ,
&n) ;
pri
ntf("\nEnt erthev al
ue:"
);
for(i
=0; i
<n;i++)
scanf (
"%d" ,
&a[ i
])
;
for(i
=0; i
<n-1;i++)
{
for(j
=i+1; j
<n;j++)
{
i
f(a[i
]>a[j])
{
temp=a[ i];
a[i
]=a[j
];
a[j
]=temp;
}
}
}
pri
ntf("\nTheAscendi ngOr der:\
n");
for(i
=0; i
<n;i++)
pri
ntf("\n%d" ,
a[i]
);
getch();
}

RESULT:

ASCENDI
NGORDER

14
*
***
***
***
***
***
***

Ent
ert
henumberofi
tem:
5

Ent
ert
hev
alue:

55

66

99

47

25

TheAscendi
ngOr
der

25

47

55

66

99

EX.
NO:06
PALI
NDROME
DATE:

AI
M:

15
Towrit
eaCpr
ogr
am t
ocheckwhet
hert
hegi
venst
ri
ngi
sapal
i
ndr
omeornotusi
ng
poi
nter
s.

ALGORI
THM:

St
ep1:St
artt
hepr
ocess.

St
ep2:Decl
aret
hepoi
nterv
ari
abl
es*
p1,
*p2.

St
ep3:Gett
hest
ri
ngusi
ngscanfst
atement
.

St
ep4:Copyt
hest
ri
ngat
ob.

St
ep5:Rev
erset
hest
ri
ngb.

St
ep6:Assi
gnt
hest
ri
ngaandbt
opoi
nterv
ari
abl
ep1,
p2.

St
ep7:Compar
ethest
ri
ngsp1&p2,
i
fthev
aluei
sa0,
displ
ayt
her
esul
t


str
ingi
sapal
i
ndr
ome”
.

St
ep8:El
sedi
spl
ayt
her
esul
t“st
ri
ngi
snotapal
i
ndr
ome”
.

St
ep9:St
opt
hepr
ocess.

CODI
NG:

/*PALINDROME*
/
#i
ncl
ude<stdi
o.h>
#i
ncl
ude<stri
ng.h>

16
#include<coni o.
h>
voidmai n(
)
{
chara[ 10],
b[10],
*p1,
*p2;
cl
r scr();
printf(
"\n\t\
tPALI NDROME");
printf(
"\n\t\
t****
******
***
*")
;
printf(
"\nEnterast r
ing:"
);
scanf ("
%s" ,
&a);
strcpy(b,a);
strrev(b);
p1=a;
p2=b;
i
f(st r
cmp( p1,p2)
==0)
printf(
"\nThest ri
ngisapalindr
ome");
else
printf(
"\nThest ri
ngisnotapalindr
ome")
;
get ch();
}

RESULT:

PALI
NDROME

*
***
***
***
***
*
17
Ent
erast
ri
ng:
HELLO

Thest
ri
ngi
snotapal
i
ndr
ome

PALI
NDROME

*
***
***
***
***
*

Ent
erast
ri
ng:
MALAYALAM

Thest
ri
ngi
sapal
i
ndr
ome

EX.
NO:07
COUNTI
NGTHENUMBEROFVOWELS
DATE:

AI
M:

18
Towr
it
eaCpr
ogr
am t
ocountt
henumberofv
owel
sinagi
vensent
ence.

ALGORI
THM:

St
ep1:St
artt
hepr
ocess.

St
ep2:Readt
hesent
enceusi
ngget
s()f
unct
ions.

St
ep3:Checkt
hechar
act
ersoft
hesent
encet
ofi
ndt
henumberofv
owel
s

Pr
esent
.

St
ep4:I
fpr
esent
,incr
ementt
hev
ari
abl
etocountt
henumberofv
owel
s.

St
ep5:Pr
intt
henumberofv
owel
spr
esenti
nthesent
ence.

St
ep6:St
opt
hepr
ocess.

CODI
NG:

#incl
ude<stdi
o.h>
#incl
ude<conio.
h>
#incl
ude<stri
ng.h>
voidmain()
{
19
charst r[50] ;
i
ntv owel s=0, i
=0;
cl
rscr() ;
pri
ntf("\n\ t\tCOUNTI NGVOWELS" )
;
pri
ntf("\n\ t\t*************
***
***"
);
pri
ntf("\n\ t\tEnterast r
ing:"
);
gets(str);
while( str[i
]!='\
0')
{
i
f(str
[i]=='A' |
|str
[i
]=='a'|
|
str[
i]
==' E'||str[
i]
=='e'|
|
str[
i]
==' I
'|
|st r
[i]
=='i
'|
|
str[
i]
==' O'||
st r[
i]
=='o'|
|
str[
i]
==' U'||
str[i
]=='u')
vowel s++;
i
++;
}
pri
ntf("\n\ n\tThet otalnumberofvowel
sis:
%d"
,vowel
s);
getch() ;
}

RESULT:

COUNTI
NGVOWELS

*
***
***
***
***
***
***
20
Ent
erast
ri
ng:
TAMI
L

Thet
otal
numberofv
owel
sis:
2

COUNTI
NGVOWELS

*
***
***
***
***
***
***
*

Ent
erast
ri
ng:
POSI
TIVE

Thet
otal
numberofv
owel
sis:
4

EX.
NO:08
FACTORI
ALUSI
NGRECURSI
ON
DATE:

AI
M:

21
Towr
it
eaCpr
ogr
am t
ofi
ndt
hef
act
ori
alofagi
vennumberusi
ngr
ecur
siv
efunct
ion.

ALGORI
THM:

St
ep1:St
artt
hepr
ocess.

St
ep2:I
nputt
henumber
sofn.

St
ep3:Fi
ndt
hef
act
ori
alv
alueusi
ngt
her
ecur
siv
efunct
ion.

St
ep4:Pr
intt
her
esul
ts.

St
ep5:St
opt
hepr
ocess.

CODI
NG:
-

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

l
ongi
ntf
act
(i
ntk)
{
22
i
f(k==0)
return1;
else
returnk* fact(
k-1);
}
voidmai n()
{
i
ntn;
clrscr(
);
printf(
"\n\t\tFACTORI AL"
);
printf(
"\n\t\t****
*****
**")
;
printf(
"\nEnt eranumber :
");
scanf (
"%d" ,
&n) ;
printf(
"\nFact ori
alval
ue=%d",f
act
(n)
);
get ch(
);
}

RESULT:

FACTORI
AL

*
***
***
***
*

Ent
eranumber
:5
23
Fact
ori
alv
alue=120

EX.
NO:09
STUDENTMARKSHEET
DATE:

AI
M:

Tocr
eateaCprogram t
opr i
ntthest
udent’
sMar ksheetassumingrno,nameand
mar
ksin5subj
ect
si nastr
uctur
eandalsocreat
eanarrayofstr
uctur
eandpr i
ntt
he
24
mar
ksheeti
nuni
ver
sit
ypat
ter
n.

ALGORI
THM:

St
ep1:St
artt
hepr
ocess.

St
ep2:Cr
eat
east
ruct
uref
ormar
ksheetandt
henReadt
hev
aluesofr
egnumber,

name,
subj
ect
,subj
ectcodeandmar
ks.

St
ep3:Pr
intt
hev
aluesofr
eg.
no,
name,
mont
h&y
ear
,subj
ect
s,subj
ect
code,

subj
ectname,
maxi
mum mar
kandmar
ksscor
edi
nuni
ver
sit
ypat
ter
n.

St
ep4:Pr
intt
henot
ebel
ow40i
sfai
l
.

St
ep5:St
opt
hepr
ocess.

CODI
NG:

#include<stdi
o.h>
#include<coni
o.h>
structstudent
{
i
ntr no,y
ear,maxmark;
charname[ 10],
month[
5];

25
i
ntm[ 6]
;
str
uctinf
ormati
on
{
charsubcode[
10],
ti
tl
e[50]
;
}i
nfo[
6];
}st
ud;

voidmai n(
)
{
i
nti;
clr
scr()
;
pri
ntf("
\n\t\t\
tMARKSHEETGENERATI ON" );
pri
ntf("
\n\t\t\
t* **************
** *
* ***
* **
* "
);
pri
ntf("
\nEnt erthest udentr egno: ");
scanf("
%d" ,
&st ud.
rno) ;
pri
ntf("
\nEnt erthest udentname: ");
scanf("
%s" ,&stud.name) ;
pri
ntf("
\nEnt erthemont handy ear :"
);
scanf("
%s%d" ,
&stud.mont h,
&stud. year);
for(
i=0;
i<5;i
++)
{
pri
ntf("
\nEnt erthesubj ectcode: ");
scanf("
%s" ,
&stud.info[i]
.subcode) ;
pri
ntf("
\nEnt erthesubj ectt i
tl
e:");
scanf("
%s" ,
&stud.info[i]
.ti
tl
e);
pri
ntf("
\nEnt erthest udentmaxi mum mar k:")
;
scanf("
%d" ,
&st ud.
maxmar k);
pri
ntf("
\nEnt erthest udentmar k%d: "
,i+1);
scanf("
%d" ,
&st ud.
m[ i]
);
clr
scr()
;
}
pri
ntf("
\n\t\t\
t\tMARKSHEET" );
pri
ntf("
\n\t\t\
t\t** *
** ******
**")
;
pri
ntf("
\n\n\t\tRegno: %d\ t
Name: %s\ t
Mont h&Year:
%s%d",
stud.rno,stud.name,st
ud.
month,
stud.
year
);
pri
ntf("
\n\n\t=================================================" );
pri
ntf("
\n\tSubcode\ tSubName\ tMaxmar k\tMarkScor
d")
;

for(
i=0;i
<5;
i++)
{
pri
ntf(
"\n\
t%s\t\t
%s\t\t
%d\ t
\t%d",
stud.i
nfo[
i]
.subcode,
stud.i
nfo[
i]
.t
it
le,
st
ud.maxmar k,st
ud.m[i]
);
}
pri
ntf(
"\n"
);
pri
ntf(
"\n_____
______
_____
_ _
_______
_ _
______
________
____
_ _
______
_____"
);
pri
ntf(
"\nNote:Below40isf ail
")
;
26
get
ch(
);
}

RESULT:

MARKSHEETGENERATI
ON

*
***
***
***
***
***
***
***
***
*

Ent
ert
hest
udentr
egno:
001

27
Ent
ert
hest
udentname:
ARJUN

Ent
ert
hemont
handy
ear
:MAR2013

Ent
ert
hesubj
ectcode:
11T

Ent
ert
hesubj
ectt
it
le:
TAMI
L

Ent
ert
hest
udentmaxi
mum mar
k:100

Ent
ert
hest
udentmar
k1:
64

Ent
ert
hesubj
ectcode:
11E

Ent
ert
hesubj
ectt
it
le:
ENGLI
SH

Ent
ert
hest
udentmaxi
mum mar
k:100

Ent
ert
hest
udentmar
k2:
69

Ent
ert
hesubj
ectcode:
12A

Ent
ert
hesubj
ectt
it
le:
C

Ent
ert
hest
udentmaxi
mum mar
k:100

Ent
ert
hest
udentmar
k3:
88

Ent
ert
hesubj
ectcode:
12B

Ent
ert
hesubj
ectt
it
le:
DIGI
TAL

Ent
ert
hest
udentmaxi
mum mar
k:100

Ent
ert
hest
udentmar
k4:
78

Ent
ert
hesubj
ectcode:
1AA

Ent
ert
hesubj
ectt
it
le:
MATHS

Ent
ert
hest
udentmaxi
mum mar
k:100

Ent
ert
hest
udentmar
k5:
38

28
MARKSHEET

*
***
***
***
***

Regno:
101 Name:
ARJUN Mont
h&Year
:MAR2013

==============================================================

Subcode SubName Maxmar


k Mar
kScor
d

11T TAMI
L 100 64

11E ENGLI
SH 100 69

12A C 100 88

12B DI
GITAL 100 78

1AA MATHS 100 38

_
___
___
___
___
___
___
___
___
___
___
___
___
___
___
___
___
___
___
___
___
___
___
__

Not
e:Bel
ow40i
sfai
l

EX.
NO:10
SUM OFMATRI
XUSI
NGPOI
NTERS
DATE:

AI
M:

TocreateaCprogr
am usi
ngpoint
erst
oaddt
womat
ri
cesandt
oret
urnt
he
r
esul
tantmat
ri
xt ot
hecall
i
ngfunct
ion.
29
ALGORI
THM:

St
ep1:St
artt
hepr
ocess.

St
ep2:Gett
hei
nputf
ornumberofr
owsandcol
umns.

St
ep3:Gett
hev
aluef
ormat
ri
xa[
][
]andst
orei
tinSpeci
fi
edaddr
essusi
ngpoi
nter
s.

St
ep4:Si
mil
arl
ygett
hev
aluef
ormat
ri
xb[
][
].

St
ep5:Cal
l
ingt
hef
unct
ionadd(
)tosum oft
womat
ri
xandst
oret
hemat
ri
xinan

ar
rayofc[
][
].

St
ep6:Ret
urnt
hesum ofmat
ri
xval
uef
rom f
unct
ion.

St
ep7:Pr
intt
hesum ofgi
venmat
ri
x.

St
ep8:St
opt
hepr
ocess.

CODI
NG:

#incl
ude<stdi
o.h>
#incl
ude<coni
o.h>
voidadd(i
nta1[10][
10],
intb1[10]
[10],
i
ntc1[
10]
[10]
,
int
,i
nt)
;
voidmain()
{
i
nta[10][
10],
b[10]
[10],
c[
10][10],
n,
m, i
,
j;
cl
rscr(
);
30
pri
ntf("\n\t\tSUM OFMATRI X")
;
pri
ntf("\n\t\t=============" );
pri
ntf("\nEnt erM&N: ")
;
scanf("%d%d" ,
&m, &n) ;
pri
ntf("\nEnt ermat rixA:\n")
;
for(i
=0; i
<m; i++)
{
for(j
=0; j
<n;j++)
scanf("%d" ,
*(a+i)+j
);
}
pri
ntf("\nEnt ermat rixB:\n")
;
for(i
=0; i
<m; i++)
{
for(j
=0; j
<n;j++)
scanf("%d" ,
*(b+i)+j)
;
}
add(a,b,c,m,n);
pri
ntf("\nTher esultis:
\n");
for(
i=0;i<m; i
++)
{
for(
j=0;j<n;j
++)
{
pri
ntf("%d\ t"
,*(*(
c+i)+j))
;
}
pri
ntf("\n")
;
}
getch();
}
voidadd( i
nta1[ 10][10],
intb1[10]
[10]
,
intc1[
10]
[10]
,
intm1,
i
ntn1)
{
i
nti,j
;
for(i
=0; i
<m1; i
++)
{
for(j
=0; j
<n1; j
++)
{
c1[i
][j
]=*(*(a1+i)+j)
+* (*
(b1+i)+j
);
}
}
ret
urn;
}

RESULT:

SUM OFMATRI
X

=======+======

Ent
erM&N:
22

31
Ent
ermat
ri
xA:

12

38

Ent
ermat
ri
xB:

56

83

Ther
esul
tis:

6 8

11 11

EX.
NO:11
FI
LECOMPARI
SION
DATE:

AI
M:

Towrit
eaCprogr
am tocr
eat
etwof
il
esnamesar
easar
gument
sandcheckwhet
her
thef
il
econt
ent
saresameornot
.
32
ALGORI
THM:

St
ep1:St
artt
hepr
ocess.

St
ep2:Cr
eat
etwof
il
esa.
txtandb.
txt
.

St
ep3:Decl
arepoi
nterv
ari
abl
e*f
p1,
*f
p2.

St
ep4:Opent
het
wof
il
esi
nreadmode.

St
ep5:Gett
hecont
entf
ort
wof
il
esusi
ngf
get
c()Funct
ion.

St
ep6:Compar
ethet
wof
il
es.

St
ep7:I
fcont
ent
sar
esamedel
etet
hesecondf
il
eandDi
spl
ay


SECONDFI
LEREMOVED”
.

St
ep8:El
sedi
spl
ay“
CONTENTSNOTSAME”
.

St
ep9:St
opt
hepr
ocess.

CODI
NG:
-(f
cmp.
c)

#i
ncl
ude<stdi
o.h>
#i
ncl
ude<conio.
h>
#i
ncl
ude<stri
ng.h>
#i
ncl
ude<stdl
ib.
h>

v
oidmai
n()
{

33
i
ntr esult
=cmpfi
les(
);
pri
nt f
(“\
n%d”,r
esult
);
getch();
cl
rscr();
}

i
ntcmpf il
es( )
{
charf i
le1[]
=” a.txt
”;
charf i
le2[]
=” b.txt”
;
charc1[ 15],c2[15];
FILE*fp1,*fp2;
fp1=fopen( fil
e1, "
r"
);
fp2=fopen( fil
e2, "
r"
);
fgets(c1,16,fp1) ;
fgets(c2,16,fp2) ;
i
f( st
rcmp( c1, c2)==0)
{
remov e(fil
e2) ;
print
f("\nSecondFi l
eRemoved"
);
return1;
}
else
{
print
f(“\nCont entnotsame”
);
return0;
}
}

RESULT:

C:
\TC\
BIN>edi
ta.
txt

C:
\TC\
BIN>t
ypea.
txt

NANDHAARTS

34
C:
\TC\
BIN>edi
tb.
txt

C:
\TC\
BIN>t
ypeb.
txt

NANDHA

Cont
entnotsame

C:
\TC\
BIN>edi
ta.
txt

C:
\TC\
BIN>t
ypea.
txt

NANDHAARTS

C:
\TC\
BIN>edi
tb.
txt

C:
\TC\
BIN>t
ypeb.
txt

NANDHAARTS

SecondFi
l
eRemov
ed

EX.
NO:12
COMMANDLI
NEARGUMENTS
DATE:

AI
M:

35
Towri
teaCprogr
am whi
chtakesaf
il
eascommandli
neargumentwit
hfi
l
e
pr
ocessi
ngf
orcount
ingt
henumberofchar
act
ers,
wor
dsandlines.

ALGORI
THM:

St
ep1:St
artt
hepr
ocess.

St
ep2:Gett
hecommandl
i
near
gument
sinmai
n()
.

St
ep3:Opent
wof
il
es,
onei
nreadmodeandanot
heri
nwr
it
emode.

St
ep4:Readt
hef
il
econt
ent
susi
ngget
c()f
unct
ionupt
otheendoff
il
e.

St
ep5:Usi
ngi
fst
atement
,cal
cul
atet
henumberofchar
act
ers,
wor
dsandl
i
nes

i
nthef
il
es.

St
ep6:Wr
it
ethecont
ent
sfr
om f
il
e1t
ofi
l
e2usi
ngput
c()f
unct
ion.

St
ep7:Pr
intt
hev
aluesofnumberofchar
act
ers,
wor
dsandl
i
nes.

St
ep8:Cl
oset
hef
il
e.

St
ep9:St
opt
hepr
ocess.

CODI
NG:
-(pgm12.
c)

#incl
ude<stdi
o.h>
#incl
ude<coni
o.h>
voidmain(i
ntargc,
char*
argv
[])
{
i
ntcc,wc,l
c;

36
FILE* f
p1, *f
p2;
charc;
clrscr();
i
f(ar gc!=3)
{
printf("
\ n\t\
tCOMMANDLI NEARGUMENT" )
;
printf("
\ n\t\
t* *
* **
******
*****
******
****
**")
;
printf("
\ nUSAGEI SCOMMAND
<SOURCEFI LE,
DESTI NATIONFILE>"
);
exit();
}
fp1=f open( argv[1],
"r
");
i
f(fp1==NULL)
printf("
\ n\tfi
lecannotbeopened" )
;
fp2=f open( argv[2],
"w")
;
i
f(fp2==NULL)
printf("
\ n\tfi
lecannotbeopened" )
;
cc=wc=0;
l
c=0;
whi le((
c=get c(fp1))!
=EOF)
{
cc++;
i
f((c==' ')|
|(
c=='\n')
)
wc++;
i
f(c==' \n')
l
c++;
put c(c,
fp2) ;
}
printf("
\ n\tCOMMANDLI NEARGUMENTS" )
;
printf("
\ n\t-
--
---
---
--
--
---
--
--
--
--
--
--
--
---
--
--
--
--
--
-"
);
printf("
\ n\tNO. OFCHARACTERS: %d",
cc);
printf("
\ n\tNO. OFLI NES:%d",
lc);
printf("
\ n\tNO. OFWORDS: %d" ,
wc);
fclose(f p1);
fclose(f p2);
get ch();
}

RESULT:

COMMANDLI
NEARGUMENT

*
***
***
***
***
***
***
***
***
***

37
C:
\TC\
BIN>copycona.
txt

NandhaAr
tsAndSci
enceCol
l
ege

^
Z

1f
il
e(s)copi
ed.

C:
\TC\
BIN>t
ypea.
txt

NandhaAr
tsAndSci
enceCol
l
ege

C:
\TC\
BIN>pgm12a.
txtb.
txt

COMMANDLI
NEARGUMENTS

-
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--

NO.
OFCHARACTERS:
32

NO.
OFLI
NES:
1

NO.
OFWORDS:
5

38

You might also like