Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

J

ati
yaKabiKaz
iNaz
rulI
slamUni
versi
ty
T
rishal
,My
mensi
ngh

Report
On
Basi
cCPr ogram
Cour
seName:Comput erProgr
ammi
ng
CourseCode:CSE-101

Submit
tedBy
:
HimelAhmed
Roll
:19102927
Session:2018-
19
Dept.ofElect
ri
cal
andEl
ect
roni
cEngi
neer
ing
Jat
iyaKabiKaziNazr
ulI
slam Uni
ver
sit
y

Submitt
edTo:
I
ndraniMandal
Assi
stantpr
ofesssor
Dept
.ofComput erSci
enceandEngi
neer
ing
Jat
iyaKabiKaziNazr
ulI
slam Uni
ver
sit
y

Submi
ssi
onDat
e:22/
08/
2020
1.Exper
imentName:Wr
it
eapr
ogr
am t
hatpr
intamessage"
Hel
loWor
ld"
.

Obj
ect
ives:Tobef
ami
l
iarwi
tht
hecpr
ogr
am t
hroughHel
l
oWor
ldpr
int
ing.

Pr
ogr
am Code:

#incl
ude<stdi
o.h>
intmain()
{
pri
ntf
("Hell
oWor l
d")
;
ret
urn0;
}

Out
put
:Hel
l
oWor
ld

Discussi
on:I
nthi
scpr
ogr
am basedont
hef
ocusedt
ounder
standaboutcl
i
brar
y
functi
onpri
ntf
.

2.Exper
imentName:Wr
it
eapr
ogr
am t
hatpr
intamessage"
Hel
loWor
ld"
wit
husingarr
ay.

Obj
ect
ives:Pr
int
ing"
Hel
l
oWor
ld"onscr
eenwi
thusi
ngar
raybycodebl
ocksI
DE.

Pr
ogr
am Code:

#i
nclude<stdi
o.h>
i
ntmai n(
)
{
chara[30]={
'H',
'
e',
'
l'
,
'l
'
,'
o'
,'
',
'
W',
'
o',
'
r'
,'
l
',
'
d'}
;
i
nti ;
for(i
=0;
i<11;
i++)
{
pri
ntf
("%c"
,a[i
])
;
}
retur
n0;
}
Out
put
:Hel
l
oWor
ld

Discussion:Weusedar raytoprint"HelloWor l
d".Arr
ayindexst art
satzer o.Sot heindex
of0r ef
erencest hef i
rstelementandi ndexof1r efer
encest he2ndel ement .Inthisway
allt
heindexofar r
ayr eferenceev erylet
terof"HelloWorld"onebyone.Thel oopcontrol
vari
able'i
'isinit
ial
izedto0.Thent heexpressi
oni <11isevaluated.Sincethecondi ti
onis
tr
uet heforloopbegi nsr unning.Var i
able'
i'i
sincrementi
ng.Thepr ocesscont inuesunti
l
i
ndexequal st o10.Thel i
braryfunctionprint
f()i
susedt odisplay"HelloWor ld"on
screenand%cspeci f
iest hatthepr i
ntedoutputisacombi nationofchar acter.

3.Exper
imentName:Wr
it
eapr
ogr
am t
hatpr
intt
wov
aluesaandbwi
th
usi
ngarray
.
Obj
ect
ives:Pr
int
ingt
wov
aluesonscr
eenwi
thusi
ngar
ray
.

Pr
ogr
am Code:

#i
nclude<stdio.
h>
i
ntmai n()
{
i
nta=10, b=20;
i
nti ,
c[9]
;
c[0]=a;
c[1]=b;
for(i
=0;i
<2;i
++)
{
pri
ntf(
"%d\t"
,c[
i]
);
}
return0;
}

Out
put
:10 20

Discussi
on:Usingarray,i
thasbeenprint
edtwov al
ues.Ar
rayi
ndexst
art
satzero.So
theindexof0referencesthefi
rstel
ementandindexof1refer
encest
he2ndelement.
Theloopcontrolvari
able'
i'i
sini
ti
ali
zedto0.

4.Experi
mentName:Wri
teaprogr
am t
hatpr
intt
wov
aluesaandbf
rom
thekeyboar
dwit
husingar
ray
.
Obj
ect
ives:Tounder
standt
wov
aluesf
rom t
hekey
boar
dwi
thusi
ngar
ray
.

Pr
ogr
am Code:

#include<st dio.h>
i
ntmai n()
{
i
ntv alues[2];
printf
("Enterthev al uesofaandb:\n"
);
for(i
nti=0;i<2;++i)
{
scanf("%d",&v alues[i
]);
}
printf
("Displayingt hev al
uesofaandb:\n"
);
for(i
nti=0;i<2;++i)
{
pri
ntf("
%d\ n" ,v
alues[i])
;
}
return0;
}

I
nput
:Ent
ert
hev
aluesofaandb:
5
6

Out
put
:Di
spl
ayi
ngt
hev
aluesofaandb:
5
6

Di
scussi
on:Usi
ngscanfl
i
brar
yfunct
ion,
twov
aluesar
etakenf
rom t
hekey
boar
d.Ar
ray
i
ndexstar
tsatzer
o.Sotheindexof0referencesthe1stel
ementandi
ndexof1r
efer
encest
he
2ndel
ement.Theloopcont
rolvar
iabl
e'i
'isini
tial
i
zedto0.

5.Exper
imentname:Wr
it
eapr
ogr
am t
oaddt
wonumberaandbwi
th
usi
ngarray
.

Obj
ect
ives:Tobef
ami
l
iarwi
thaddi
ngt
wonumbert
hroughusi
ngar
ray
.

Pr
ogr
am Code:

#i
ncl
ude<st
dio.
h>
i
ntmai n()
{
i
ntc[ 9]
,i
,
sum=0;
print
f("
Entertheval
uesofaandb:
\n"
);
for(i
=0;
i<2;
i++)
{
scanf(
"%d",
&c[i
])
;
}
for(i
=0;
i<2;
i++)
{
sum=sum+c[ i
];
}
print
f("
a+b=%d" ,
sum);
return0;
}

Input
:Ent
ert
hev
aluesofaandb:
1020

Out
put
:a+b=30

Discussion:Usingar ray,t
wov al
uesar etakenfr
om thekeyboar
dandaddedt wov al
ues.
Thesum i sprintedusi ngthepri
ntffunct
ion.Arr
ayindexstar
tsatzer
o.Sotheindexof0
referencesthe1stel ementandi ndexof1r ef
erencesthe2ndelement
.Theloopcontrol
variable'
i'
isinit
ial
izedt o0.

6.Exper
imentname:Wr
it
eapr
ogr
am t
osubt
ractt
wonumberaandbwi
th
usi
ngarray
.

Obj
ect
ives:Tobef
ami
l
iarwi
thsubt
ractt
wonumbert
hroughusi
ngar
ray
.

Pr
ogr
am Code:

#i
ncl ude<stdio.h>
i
ntmai n(
)
{
i
ntc[ 9]
,
i,
sub=0;
printf("
Enterthev al
uesofaandb:
\n"
);
for(i=0;
i<2;
i++)
{
scanf (
"%d",&c[i
])
;
}
for(i
=0;
i<2;
i++)
{
sub=c[0]
-c[
1];
}
print
f("
a-b=%d",sub)
;
retur
n0;
}

Input
:Ent
ert
hev
aluesofaandb:
2010

Out
put
:a-
b=10

Discussion:Usi
ngarr
ay,twovaluear et
akenf r
om thekeyboardandsubtract
edtwo
values.Thesubtr
act
edv al
ueisprintedusi
ngt hepri
ntff
unction.Arr
ayindexstar
tsat
zero.Sot hei
ndexof0refer
encest he1stelementandindexof1r efer
encesthe2nd
element.Theloopcontr
olvari
able'i
'isi
nit
iali
zedto0.

7.Exper
imentname:Wr
it
eapr
ogr
am t
omul
ti
plyt
wonumberaandbwi
th
usi
ngarray
.

Obj
ect
ives:Tobef
ami
l
iarwi
thmul
ti
plyt
wonumbert
hroughusi
ngar
ray
.

Pr
ogr
am Code:

#i
ncl ude<stdio.h>
i
ntmai n(
)
{
i
ntc[ 9]
,
i,
mul =1;
printf("
Enterthev aluesofaandb:
\n"
);
for(i=0;
i<2;
i++)
{
scanf (
"%d",&c[i
]);
}
for(i=0;
i<2;
i++)
{
mul =mul*c[i];
}
printf("
a*b=%d" ,
mul )
;
return0;
}

Input:Ent
ert
hev
aluesofaandb:
2010

Out
put
:a*
b=200

Discussion:Usi
ngarray
, t
wov aluesaretakenf r
om thekeyboardandmul t
ipl
i
edtwo
values.Themulti
pli
edvalueispr i
ntedusingtheprint
ffunct
ion.Arr
ayindexstar
tsat
zero.Sot hei
ndexof0referencest he1stelementandindexof1r efer
encesthe2nd
element.Theloopcontrolvar
iable'i
'i
siniti
ali
zedto0.

8.Exper
imentname:Wr
it
eapr
ogr
am t
odi
vi
det
wonumberaandbwi
th
usi
ngarray
.

Obj
ect
ives:Tobef
ami
l
iarwi
thdi
vi
det
wonumbert
hroughusi
ngar
ray
.

Pr
ogr
am Code:

#i
ncl ude<stdio.h>
i
ntmai n(
)
{
i
ntc[ 9]
,
i;
fl
oatdi v;
printf("
Enterthev aluesofaandb:
\n"
);
for(i=0;
i<2;
i++)
{
scanf (
"%d",&c[i
]);
}
for(i=0;
i<2;
i++)
{
div=c[0]/
c[1];
}
printf("
a/b=%. 2f
",
div);
return0;
}

Input
:Ent
ert
hev
aluesofaandb:
2010

Out
put
:a/
b=2
Discussion:Usingar
ray,twovaluesar
etakenfrom t
hekeyboardanddiv
idedtwov alues.
Thedividedv al
ueispri
ntedusingthepri
ntff
uncti
on.Ar
rayindexst
art
satzero.Sot he
i
ndexof0r efer
encesthe1stelementandindexof1ref
erencesthe2ndelement.The
l
oopcont r
olvari
abl
e'i
'isini
ti
ali
zedto0.

You might also like