0% found this document useful (0 votes)
18 views19 pages

module 4

The document discusses functions in programming, including definitions, types, and examples of function calls and parameters. It covers built-in functions, user-defined functions, and recursive functions, explaining how to declare and use them in code. Additionally, it highlights the importance of variable scope and parameter passing mechanisms.
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)
18 views19 pages

module 4

The document discusses functions in programming, including definitions, types, and examples of function calls and parameters. It covers built-in functions, user-defined functions, and recursive functions, explaining how to declare and use them in code. Additionally, it highlights the importance of variable scope and parameter passing mechanisms.
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/ 19

MODULEA

FONCTIONS.
D FuCTioN that kgto pe
ia gron
atatenmeni
Funthon
neptikor
eCodis
tk
avnd
* h Main obfeve i o
am

>Funthon dedinihon
funehon. namelpaianues lot)

dclaanhin;
Vaiabla

lo a
AAKknnen ;
-Conputid );
aukun (Vaue

vauu tlat unhien


h dak b loal et
MAYke i n t e , chaL
anyhing kiu
auluin anythin a
*
J
u unthon des not
* hi
b
ttu opuulie
i u qivns Lnsut a
+Paramutr
iithin funeton
Vaniablus
ad onby
Vaiable an

lo unen
twns Auult
Amnt
ypes o Funtond.
Fundkons rondy clhad
a
a ioo p
a)Butltm untbäv
Us dlind ncnon

abuilt m untkon.-
Blt unukons ae h unehon that a

Rhaay Nan lxannp tnder la

Ma kb Aay .qnt, poeA) math.h


Aandand Rbvay stdids.h

chanal kbaay ialat) clgpe.


Ltandánd ifo Mbray i ) a ) tdio. h

1
bUso dJind unken.
Th bule undhons providd yc
allonss
peoaming tonmid Lnions, hincu C uo

%oda() tala Kiuis ehen kuntkons pertM ape


ksk. The an Called as aun deliontduntens.
pAogram k add de
roqtam s add a N
ithout aim uniho
e undh ns.
4intdxstdio.h> in cudeitdio.hs
*intmde lonio.h» #Tnued tonio,h>
Vid Maml) void addl)
n a 0 , b:20, &uum
int az, b:3, um;
um: a +b;
Paintl(Tke um b/-dlo", Au)
PAin Te um d\n"Aum)
qelthl) Void Maun)

ttsul)
add t),
guttht,

Slun Junher [usw dufined huntkr


1ha a 3 tuunk m st olukind unto
a. Funtkn olelnkon
bFuntan Cal
. Funthen delwukon
a Funtkon deinihon.
Funthon dehtnikor pwidu tn acnal bidy
unuien.
Funtkan ds dukimed as

uun uncionname lparanmeen ka


ol Vavalls duuanha

Aumn (Vauu-otud), t.
w add lmt a, it b)

Xum at

bFunhon(au:
Te enteuhon alom smo fom Maln
non, avoui a

inide a Main mnkon in lalls ntken (all


unwo

inthnditkdio. kA
unt add (iak a, ind b)
rid Mam )

nt Az 10, b>.80, AUm

um Add la,b),

Funken deulauhen (b43 Funtkon pwlype


kllk Ka
uncion dtelaukm ( Juntkm ms
re, kuuns ype
and
paau
Compn abn a untkn

untkmnan lparanetii liat);


kman:Akanlgpe
n add lt'a, nt b);
ocal Vaviab Gleb VaiaL,
L e l Vaviabls auo tallek inianad
ae as
vakallu
Funtko inchudinn k maLn c)nthon dulau tke
Vaai abus ko ak»L ktpeAa Vawus, fkia Vamnkla a
Clde vaiabi
T leul Vaiabls a acunille esy sdii. ta
dumd
Vaiab alko Calld au tan Vaials
Global a

Tke a Vaiablu shich lan be uad e) awwilh


em a unthend a t m

allkan unehn talld rantion


Calls anelhur
Th un Km )amaunt) þrogram h ith
b Calld talking unchm,
unten
Calbing nmmkin t )
Gall
alld y Calling nnin
Te
untkm uud |
lalld nhon.
add t );

Ackaal parans tomal þaramuu


Atmal paamuus-
paumts, banaleud o

Cuinunuhon Iproqam Callunhm


ulu

FORM paamelins
oAma
FOAmal Pasanmelns ane alse (allud a u 7
TLe Paamins aNl
om tthe Calld unun

y s fontkens Baued on Parametas -

Funkons ithont pManuu ithant luon1ype


and
Funtko tlont amnmskiu } htth kafop
C Funds t t paunuis and thod Ruturn e
Fundkons ith pamndins ith Pentype
iot Rlun Tpe-
a. Fundhons ithot paumutiu and
em talling funion to
No pAamuXeN antd
xetan an Yal
Callld hundhen kici does not
#i'ndud stdio.h>

in cude klonio.h
Void addo
Veid main t)

cusul
odd (;

int um: 10,: A03

pxin ` a m h od ', 3um),

Funtkon ap void sin eaant nelw


Cud uniRen
Funthons ihonk patannlus and nalheReatn kpe
No paaamuin i pamdom (aling funthn k ke
Caud nnntlkon, » k u t u n m kanm a Valuue.

fndwmdeAstdio.h>
#im dw ktonio.h

Void maint)

in Mm
Aum- add ) ;

pint sum b d \n", Aum),


qeeht

int addt

int um, À
=10,
Bum: l+?
Aekan um

C. Funttn i panmulis and thont Rebnsn lpe


the lld
Paamulis aw
paelam Caling unthm t Value.

un ckon and ulll unhon doei mot


Aelnan a

iw uomho apueik'd aeka


#indudei tdko.hs
in ndei toMo.h>
Vord add lint &, int /)
Veid MaL )
n a 1o, b:d0,

add la,b)
etcht)

in&um iapdln' sum)

d. FunRens i lK paamtiu and koitt kakann hype.


*Pasamuliu a paed m Calllg mndhon th
ard basc on tk teived pau muln
Cald vm k n
isd altm
Vaus " l l nKon perloams
AinAnsa val.
i n t h d e r stobio. h>

int add lint i, inl i)


Void maimt)

i um, a- 10 b 20 ut);
Sum add Ca,b)
=

pain &um ihd lo", sum)

fmt adk lint å, int {


&um
kum: lt

R MmeTeR Pass1N MecHANISMS.


Iken unto Avotd, a k panamuar
& pand mo tk unuhon baa m proqramnlu

AminLmenb,

invocakon on a
Calkng sndi on
uning unun Vaable is
h a a Vaiable a) an addns
no Callud wndhons
Pasd

pawmn panamuv lihanis m

a. Ca y Vau
. Cu y uunu.
a u y Va, pand o
Vaiabte (on) a Vame
Wken
h thvotakon ,
is uatin imvei
wnhon duuung parannel painy 7
nlud as tnll hy Value lau
Vaae.

i n dude lonio.h>

in add link i, it i)
Void mauh )
= 10, bz20;
a
nt Aum,

csl d lab)
Aum bpd \n", sum)
PAAntk
getch)

in add [int t, inb

int sum
um: i4

acual palamuti , ohen


hat a and b a Valuw acbnal
add la b) i Calld tihe
n eion
,

paauln ept'ed letmal pauamtins


ddion i and ' . Vala b) Pasamuli
muthod
alud
Gau ky
*
T
a i n y Value.

t fhe
a u by uuuna tho
Vaialbles
o passu
addus
klken' an tkin unhm
h n vocun ,

wnhon dumn ieeiince- i


b &d as tall ky
n Voton
uns,
pasiay t
C dou no
kupoat danecly
d o n indiktty by pawing the Vauialle.
'tka Naluw the
Vadable and thani
XKAo nah addin.
in dudek tonio.h

Void mam C)

An um, ajo, b 20

Kum add (ka, ) ;


b d lo", Aum)
P i (* Aum
9tk
in
addtint l ,

Rlnan um

+Istud Valus a and b, addses , Valus


t
mfenuhu * R eceives
PaMd
andban papm
addon
peuim
taaaul
allud au hy eleenw
1h lonct i
oMnk nu.
*Exale homumn
AD wain
klh a C program p n
Xuonpo kAy Vaiabla.

Cal Yalue *|
i m dnde atdio.hs

i n dnde tonio.hs
Void Aut nt d, in
Void Maial)

mt ab; ttvsul,
and )
pimt Entuv e
Åarl.df.d ", xa , b),
Bwapl ab);

Vetd nonpl i k d, int 9)

d
Cau by untr
h>
hde i t dio.
in
i n cde lonio.h >

(onb Aoap| an *, m

Void MAn

ab

o 4b Valuu\n);

Atak 1-d . d " , ka ,ab)

Prin AMa sny a /d,btAlo",a,b)

1
KecuRSIVE FUNCTIONS
R ve un thona
oMundhnt allina
Aeatedhy
RRL on roamMUs neAd o h
anwl din an eni "londiXron om Mnan
ot ni i ininiiniiu lo.
Kcuive wnuions d Vm uakul to row mann
Madhemaki oblms Jka l n aco vial
,
genaaRiq fibonati se Jiu

konkal to) t
ackonnal (6): 5*+ laloaial tA)
5 4 alhsiad l
5t 4 3 a o id b)
A4t32a atoaial )
lo).
tkial
4 *3 « l
*|&0
54 A3 * 2

20

Fatko ada N
nteu n , dest by n
Facoaial o n - Mgakve
ve integu ux hare
paodineb a po aik

mn!
= n«ln -1)* [n >) - .

aNa
Nou. Fattoiia

oaram:1
#Tn cndsLstdio, h>

i m daade < tw ri o, h

Imbaborial l );
Void main U)

int , a c
saD a In");
Paint2kn e

ladnainl lint m

Aunann facoaialln-1));

> 1BDNACC SERIt-


koen a
T bona lii A4Men i a
^m
ound y ading np thu
qen bn1n 1n-tin-

o : Recunnive paman qenaih F, onai

Fln-i) + Fln )
Fln)
Fl-
F)-1

dstdio. h>
i n dund
n c c d e d lonio.h>

n);
bnacei limt
Tn
Void

dnlO,
int m,i,x;
primt&aln n\n");
ta 1-dk),
Sis iln");
rn bonae

1bnotui i),
print -d\n", x),
2
L
manel m n)

Soy nk

b a s Complui aulay a paam

inmda skdio.h
*in tae i lonio.h>
ink Aum (int n[ D

V mam l)

MasulsT o, 2 30,40, So,


hun (aka);

mt Aum 0,

ol:0 14S, i1)

Sum um n;

p'r Sum n ' , Bum)


fain sknns aneben

Tksinas a eatd as thaatoy.a a w


thenere ulu a aings k unman

Ve m i tole

B i u s ane
he 4ng th k pamd uut ha dedand as m

n duyimu
diplay (tha anael)

bTwnhon ve lge mwt shos ttat tko agument


0
a abuin
vd digldhar sl
hove iung
CA Cau k t h unem must
h
a

nenal aguaent6
A aumy

t h en Ao suiisls as

dinp (namu),

You might also like