Gagan Parmar Unit 3 C Language
Gagan Parmar Unit 3 C Language
cerelitien is tested
the shila Jopp, the
Tn
0 Whila Joop- tatemeuts is executed.
befo auy the
[Pre test p
Statemeuts X
statemeut y
Corditien
Truu
Fale
Statemeut z
Flwchant o whie icop
Syntar hile op -
statemets x ;
chile (enditien)
Statemeut Y
Cerdiien ubdate )
Statemet Zj
(
(2) Do white loop
cendiien is tested ot
Ln dodile loop, he test
Aoop)
the end o the oop. [Post-test
statewdut X
Statemeuta X)
do
staBeret Y;
ydition update;
Iadile (covditien); bdatecodiin
ex penon
statete Y
True. yditiern)
|Fala
Stateutt Z
uþdatiasncenaut (decrehkut)
(initializaien;cONditien;
fon
Statomeutej
[Gendiinckdate
COntitien
teestateunot Y
Lant
Ate
heck
for (izo; i<= o; it+)
O|2 3
itua
cd mainl)
Iinlhialiatien
int i O;
do /sbkuuds
pint ( d, i);
i=i+i; Cenditie:
hile ic=(o): l
netn j
#idude <stdioh>
i t maiu )
statenut;}
ut i;
(i=o; i<=o; i++)
for
actum o Aai O I 2 3 4 s
6 t % 9
bosttet lopp%
aetest aud
Combaison
Pre test loop Post test loop
featue
# tests
Statencuts
exeeuted
N
hopCentl
Vaiahle fdate
iteatia
# ncluce <stdio>
iut main C)
fonl;i<=lo;)
Nested Loops
#incude <stdio.h>
nt maiu ()
for (ind;i<=S;j++)
printf ('ln Pass od - ");
printt("hd,);
3
Pass 1 - 2 3 4 S
Pass 2- | 2 3 4 s
| 2 2
s S
Pan y- | 2 3
3 4 S
Pam S- |2
Centiue Statemauts
Bredk aud
biak
Vsid man () Tf oe
2. 3
iut i=1;
(i=1; i<10;t+) 'Cortu'
for
6 9
break ; / Continuej | 2 3 4
printt (" yod",i);
3
statemeut is wed to terminate tha
The boak
nearant Joop iu cohich it abbec.
execuien a< the
numbe: "))
printf ("Enden aug
Scanf ("d"n);
cshilo (n>o)
n=n/0;
ais
digits %d, c);
printf("TAenooe
a giveu no.
to tind es u digts
() WAP
#incudo <stdioh
{it s -0,dj
fjt n, S=o,dj nube:");
pintf (° Enter a
Scaur (" tod,kn);
cohile (n>o)
fd=n%lo;
S= S+d;
n=m/O)
4) factoia
#Jnclde (stdio.h>
196id nain ()
{int fact=1,n;
pitf ("bte auuy ne.:");
Soaf ("%d,kn);
cshile (n>o)
fact - factx n,
n--;
pintf("zd ', fact);
L is not Bime no]
S) WAP to tnd cshethen a gven
ven no. is pim o not.
tt tnclaude <stdlo.h
(iut i, n;
pintt ("Ete aug no!");
scauf(d",n );
tor (i= 2; i<=nj it+)
boak
if n ==i)
puidf (" Prie");
els
puntf("Net Pie"J;
fuuctien
a set l statemects that takes
fuucien is baically a
cempuatien aud producen output
inputs, þeferm seme
fuctennane (set o intute);
Retusnyke
mpostaut ease
* Therc ano toe
) Reuncbility cau be reued osa aud
One thefuuction n definad, it
aqoin
(2) Abstaction
uucten inyn pogam theu gou
the
u ane jutwingabout wide
I4 hos it oyko
dont have to coor
fuctien prototyhe)
Fuuctien declanatien (alho caledfuctien tethe compilen.
* fnaaenties o a
moaua declaing the
fu (iut, chan);
int
Name tho fuctien: fuu
Projeartio: )
fuuchien: t
e) Retunntybe ol
Nuumbn of pamete: 2
3)
Tyheot uametel: int
9
Tyhe pauamete 2! chan
6)
Examhls:
A)WAP to add toe nos.
# incude <stdio.h> IFuuction Dalaration
ut add (int, i t
);
f t a, b, c ; nos:");
paintt("Een toe
scauf (" d hd",a,Lb); /Fuctien Call
C= add(a, b); Argmerdks or Arqumets
pintf ("/%d', c); > Achual Panametev
finitien
/ Fuuctien De
i t add (iuta, iud
b)
Argmect or Paameten
>Formal Parameten
C= a bj
petun (c);
otputs:
(B) Check the t#ncludo <stdioh
#include<stcioh> char fuu (J
char fun(); (2ehnn 'a';}
j t main() lct maiu()
fchar c =funl);
fchar c-fuo;
paintt (chanacter is : hc', c):? 2cc
paidf("chanacto is
chan tn )
(hetn 'a';} a
Am:chauacte is :
Aug chanacten is:a
au cinplicit
Cay acto as
fuuctien delinitien itse euctien is dofined
x Fhe So, in cane the
fucten deelartierm, paoganmat skip fuuct
be<ore beig uncd;the
declanoten.
3
# include<sttioh>
int main ()
chan cfuc);
puintf("chaater is %c,c);
chan u( )
etn 'a';
u (iut a,int
b)
jait
a =2 j
b= 1
CALL By REFERENCE
pnameter refento semt memor
Hene both actual aud
formal
the formal paametex tcol
!
chaugemade to
locotien. Therefore,any panameten. Heu instead assing valuen,
get refleted to actual
Coe pa addrese.
#include(stlio.h> t2,
int x);
eid fn (int *, ka=looO Rb=2oOo
19id main ()
P
fiut a=1, b=2;
fun (la, kb);
pintt ("a=%d, b=hd',a,b);
o0o200o
se cuosien. an a loop.
callingitse in a act
Fuctien but it au
- looping
staBement, tatenut,
is neta neit- ebe
- It definitien,most coe
fucten
- In reavie fuc tion.
umberunig
WAPtfactial
Exaupla()
# nclude <stdio.
int fect (iut);
Led moin ()
ut n, ki
Scaunt("%d,An);
k= fact (n);
prindt("%d, k);
n)
Jnt fact (int
retun ();
int sm (int a)
{if (a==o)
etn(o);
ele ;
tun (a+ su (a-))
series using secuoien.
WAP to print the Fibonacci
Ex() include <steioh>
int fib(int);
int ma'n ()
there. tems:");
pintt(rn Ente
Scaut ("%d", n);
fon (i=o; j<n; j++) (z4)= %d", i, fb a)):?
(printt ("nFibonacci
else fib(num-2));
Iotuon (fib (nwm-i) +
Sterage Classes
classes allos wy te chauge some attibutes t
Stoage
variablee aud fuctiens.
-’ Cau chaye exteut ol a vauiable
proga
’Cau Nestict avadablo o a fuuctien toa single
negister
staic
extern
data tye vaniable-namintialvalu]
Sgrdx: stvaragclan
DAuto Steag Clas
autematically created coheu ucten is
-Ate niabla is semeved coheu fuctien is teminated.
Called aud automatically local aia bles.
-De<ault storage clan for int a;
aute nt aj
a= 11
a- l1
a= 11
4) Exterm Sterage lasses declaned
fom te comilor thata vaniable i's
- Used te in
another c-fle)
du Som external file
-Prog1am Example
Ale2.c
# include <stio.h>
t price = loo ;
ijt
13eid hikeC)
extem int pice ;
exten ued hike O) puce t t)
iut main ()
Lpindf(°Pice =d n' price);
Aike();
potf ("ice=hd \n' pice);
eton o;