0 ratings0% found this document useful (0 votes) 60 views78 pagesMODULE 3 Functions. E-Note
Module 3. Arrays strings and functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
o
Movule- TW
ThGe-1
Vas, Stings and Fonckiens -
An arn, in a Single Vartable fo Store
a Number OF Valus voit. the Same dots tye
The Clemens 0 am Oren ate Stoved
in Congeutive Storage lolatiews fn Memory.
The Name ofan orca Jo falleoed & a Number
Sn back, C1 these chumbers Stabt at 0
Exomle: fat Ast;
Tateger Array Float Avvo Chontartoe Beoey,
Assi Jo Xl] fe cial)
Acs}.do xi] )-2 cfg[B!
Ala] 32) xal2U chalsc’
| ats xfi]2-2 cLa)'D"
Alas | So S| Pe’|
eT eel cHaLE’|
int ALT float XLs3; Chay chs3 5
(Tavalid Way 24 Staring encene Mamet
Tat numLlsds
! [is] gs] 10 |ae"| 50: |
nun{s} umf} Numfsy Tums) NumlayTico tyres of an arrays:
# Single - dimensional omrey
* Mall - dimenSfonal aoreeey
Single |.
Astoy * (one dtmensfonal)
A Sing le dimens?onal coved fo @
Linear Lest Consisting
Of Same daka tyre +
Baste ProPexties of
of velabed dake thems
xb
&
Proveys :
* Avro elemerbBhould be Of Same datatyre
£ Date itins ate Sirved Conti gou8ly fo cere
& Subserter of first Stew 1S aboays Tere.
a the Index aoevou es always
I Fach Clumed
trough Name
in tefee
Pr om reed fo ater
Of the arte
Eyawle' Chay Name Dol= “ WELL Dove";
WW,
[EE
>
4 '
‘ | Of
namefod
name lit
Namel(2I
Narac Lay
Nace Lh J
Name fst
Namec 6S
‘I name Ltt
eeee
Declaration of Single dimencfonal Arays
Syotor: pawmeon med .
ty Pe oxrtoant aa ;
BxPreion must-be
aks. type, os evs fo?
jab pad, chow ae oles i
Examele
ing aleds [i | al 10 memory
ab} of} abs af) af _[ocabons
; Reseduved-
Flot xist; [ES m2 Bo by tes4
xfs x ea xia} XiKJ SPace-
Res dviegk’
Chex COAT; { [ | ae
Ci) GIs coy h A in d
The Valu Cane Strain an oxrray
(Using three method S
*& Taittal: Zation
© Asstentng Values
*& Tied Values From key Board‘Tnitial! Zatfon of Single dimensional Arye
Aasdigning the weurred Valus to a
Vakiable before Protesting Jy Called inital fabion
Arcos Umeny Gn be TntHalt Zed at the He
declarakfon -
Eyrto', Namesfteored ato value
v
tye Ooweynawne ai fs Md;
J
ti type as Posseve.
Tak, Float, Chay Feb. Value.
3s Finder) .
“jhe VaMews Ways B] Saf ial Z2 a
rc
x
| (D Taittalt 2°45 oll Se fredmennay
| (6) Readiah Prevey teitbabiZablon
| Ts bial? Zing without $i ke
1G Shing tai Bali Z ation
(i) CLaifeleny all Pecifed menexy location
Arta Gm be ini Hal? Leck at the time a
Aeclaxation (ohen thetr ‘inital Values ove Known
Oe|
Exomole' Int alT=f10 , 20, 30, ho, Soh; :
Vio |2io[s ]4 e |sie
OJ ALJ afy of3} olay
Paxtiol Arvray Ini bali Jako!
TE Nwmber Of Valuts to be tal tH ali ted
| 1h les than the Size Y an arey, then elmer,
Oke Pri tral? Lol 29 order fom 0% lo@tions The
Yemafning blanc loGbiow Tai fiali tet ko Lore -
“
Ss
: Exam 2 1 P a :
| Moone int afeted S 16 AfPend 0'S
s = {6 |0jofo
aby alt ofty aly aty
| ‘Ini tal? Jaften Without Sife'-
1 tnt xfLJ= f10,0, 12, 135;
al.
( a faecal
uf bal is
Steck xo al
Hee eventhough SP Le net srutfied. He
jassoyy StLe Lill be Set bo total number Of
|
Titel Values
Protee| Tai tiali Zaki on volte Sor"9!
| i A Seiuence Of Chavac ttrS enclo Seol writin
/ double Cun ts th a Stig ‘The Stig always
a Soe Seatac tse crag emer ae eae se ese se rar ene Merten tee|
|
|
2
Examble! Chey blJ= " KEYBoARo" 5
6) EO 665 LC) boo (I bi) bey] bat
cle viele alr leh
Nuh Cheracter
abated atend .
ASSiGnk Values fo array '-
Here we lon oustgn Sndi vidual Clumek
of an axvex Wing AESigornet OP rato &.
Examme’ Pak PLAT; te
Poy PL PRY PLS
ASSume affoy Chen IS, 10,35, S0 Gn
be Prsdtl frtasattey at Asttiow 2, 0,3,)
Pls Is5 Chis 7
| Phy pod PD Piss
Value 1S do Stove atormy Pasion a:
eld=to5 (iol | [ils] | oto ts. stn
Piss PLS PI PLy ot position ©
© elssas; Tel ETFs) 25+ sors
Pl} PLO Piet POD ot Posten S
pli £05 (io ste [fais] > Ep 15 Stoved!
Plo) PLO Phy PLY ak sino |as 0° loll fae ud
3 “Read /vovtti Siagle Dimensional Arrays!
The yead, write or Proce the an
Pkuns Ga be done toSoup, foy-looe, oly Le- love
PL -Stakiment , Switth Statsmad. uc.
To veak A date Stems from Key boaid-an
Tnblt [brady function bb Ure Sanf.()
/ Exameu'O Sant Ge Nd", Cael);
| a Ong fatQs
| Saft Yd" bale):
O preg os hens M4)
| YSantl* yd", &altDs
7
| To distlay 9 date ‘him Stor tan
Wrre4 Can be done tReovgh Pintfl) Ubvoy
funck’ on -
fev (tees TKn5 PH)
| { Ranse (eva QLD
Pf }The C- Prog fam to vada tlews § disley
Y-tken On mouth *
He include
Votd mainc)
oC
Pat 9, ald, 25
Pert (“ Enter no- a Ube (0);
Songs fd", Gad;
“Rent (* Entr Chane cxf orig \")
G for T2054 Pen shi)
“ Sang(yd * Gafid):
y ys
Patate(% AL dlomenb ate Wr");
for( teo 5 P
“Passing Entixe array. to Funckion +
= 7 the
The function Called by Parry ong
“Name Of thesdrred-
In fanctton defiattion , the Paxametty
roubt be deClavel as an Arve4 of Same. oaks tyre:
Athual Poxameter -
Ext Mainl>
pe aw [SDeL S510, 15, 20,25}
Fant (on); owt) 5
i as ae x
Aner aon ants) = |Notd func (tak ot sd) , cpbee
{ ae Fondo
t i
Soe (42 03 12255 Ht)
Patate(* Yad" Gort)
3
No te
() the Vadable av iA the Callin g
Jn CHEN deClarel gh an ore x 5 irtipers
(1) poker function GXalkd fe func the
kg
Carvey avy in Padhed “ab on cola wmtat
Example Progam’
etn clude Kh) = oft gekelta7
y
Hinclase CStdio hrs :
at}, int)
Void Ftbonai (ing?
{ Ink 1G
ve
afoJ= O03 fe Tnwal Fi bonatGnumbess */
| aLis= 15
foy (1285 Teen 4 THD
{ apiss aft-d+ Ola;
}Sees seeesaee eect
o
Motd main ea?
—
int on, 7, af Sol)
Path (> ents Vale for \w");
Stang (J.4", P95
Ftbonacd (a, n)5
Réatt(“ Cbonaced Numbes we’);
Soe (4205 ions,
{ Reratt ("hed eos atid); .
1 a Of}
ats] |
Outta | aps) 1
Fibonacci Numbers ee aly] 2
at) ats abs als abst ona {Z
| @.1 31 Ss
| The fronacci Numbers are a Series:
OF rumbers Gach that Cach Number 1A the Sum
; oY PreVirous £wW0 Numbers exccert tine Fvst
i
* Ang Setond OwnblY .Two Dimensional Arrays | (ull DimenSpovel)
Ain Axes with two Sets of Square
Brace LILT ay Called tw0- dimensional Corvayys
A hoe. dimensional deren dy UAtel vohenr
dake ‘tims ave Ovvangel fo you~ wise anc
Glan wise - :
Declaration of TW dimenpional a
Syotox ol
dale type cavvog rma Lene Leerat 5
Where y CPL Nou S°ZE
en? ~ Glunn St Le
Dota tyre - ind, Fraok , chav, oC
tat af LAS)
Gt-0 @-2 Gla lS
ho
ooo | ALI) | abel) | afIhs | apttsy
Root | ofl} apiny | anios | apatst
Rowa ales | apy | aPIbI| apsesy
hm
9bale Lea |
The owray Q declvt os 400 dimenitonal
Lolth hoo Suet brackes With You srLe
as 3B and Column Site as h
Tri tial Zation Of Tioo- dem enSional Arrays \-
Assigning A Vedutved Value fo a Varfable
be fore Processing a tai Halt Zabrow -
Syorax |
dodatyre amraynae Lor Sferra] =
i
saa
fa, ,a2---An},
Loy brs bah,
& ae
{z,)h. a4
5
Hee, aya, On ate \olues austgned £0
(St you: :
b,, b2--7 by axe Vales asianal to
grt you: ant So os
“Two _vs Sag Holt Taio aut
=k Int Halliz ng al Specified rnemor| ——
a Partial owes eai Hal Labor .a
e
oy
=
io
>
Sali bred memory locakions |
int awe La [d= f
__ Glimas 5
a.
| 9 o ie { 5, 10,153,
You's} i eae ‘ a h
aelels {5, 6, #4,
Pe i: { ¢, 4,105
i OS
Portal Array fini Hal! ballon '- :
TF number of Values to be finial: Zed
are Les than the Sie OF the away then the
element ave inihalized Room left fo Bight One
Ofte tee Othe’
Example’
Tat : lun
int alaits={ | eee
; {5,10}, p21 2
Cee) | eealiole
le
6 0
‘ {4 Ny af 10
' i 3 GP iTAGE 10
Reading and Writing tv Dimenstonal A wags!
To wad 9-d matrix Z a size MXN
and to Pint a Q-d mab¥x Zt Stlemxn WE
hove the follosing Stirs
Ste1, Id entify Parameters Lo funckion
Grven the Site Y mabrix mxa We have
bo wead elements Palo Makin Z ov Ariat elements
of mati Z-, s
Poxameters | fet ZLIbS ym, 0
Steed | Ket bye: After Seding mabty 0
Pein Hing a abix We are oot vehirning any
Value and henle,
weturn tyre Void
DES | Designing body Of the funckion '
Art Them Can be acevo by Srecifyig the
Youd fadex and Columa tadex, We Acces the ‘lens
You by you -
Elemod accened oy zedtsd
index Vadfable- Dl Ce
Pa Vee 7 Oefor (feo sicem-15 te) — for (i205 2m ite) Anas)
fortS= video, guy Prldiesdersd) Aan-otumnst
Bete aap
ZLILSL LILI A oc ey
j j
j }
C~ fun chem te Wal mabrix 0 $*Ze mxn
Void weadmabsdx (tak ZF TLRS, tat m, tat 0)
{
int i
Rone #. stems fH)
| 7 fede fees, G44)
4 Song(s id”, SL TIEAS)!
| } 4
}
Hert, vohtn Woe Pars D- dimensio Nal, are
Sou ge Le 2S oP Honal, but Coluan Size mud t be
Sec fied
9C - funckfen EO Prtnt a mokvtx ef S*Le oe
Void Printmatelx Gat ZL IL, iat m, Pat)
arty
for (i205 ? ern Pt)
fw (5-0; jeos GH)
Rite ("x gor zest);
yee we
J ss
Adsthfon of Tise mais!
ate Vartous Stes im be fy ow
bo add p00 matiles as
Steer Tdeat fy pera ntiers be function
eat ALILel, it &
tak
CYT , fae ¢ Chel,
! enk om,
Ske 2 Rebwre tyre
Veter tyre: a
f Sted! Body of Funct om
cuss = efi ILI+ BEdpss-\o3d addmabr’x (Fat af Ibe), tnt bobo], fat cle Ibeel,
Tak mm, Tak 0)
1 tat ds
| Sov (i205 <7 tt)
: for (S205 $40; i
{
ctitsd= sgt He faa robs
A, Bx.
Stes ee £0 add too matrices!
Sher: Read the S126 Of mabies m xn
Stier: Read roadrix A
Ste z'. Read marx B
letco bo! Aad mabiices Mabir C= Maki xa+ inabiy B
Stes! ubeac[Print Matix C
f Sty 6. FinishedHAGE-Q
Feo Fxarnm ta Examples \-
Single dimendional array (one dimensional) |
Progtam 1: C Progtam bo Pringy Ledgest and ft
Fh include LStdio. n>
Ane Largest (int af J,tnt n)
{
int 1, PoSs
PoS=03 &
for(tais Pens Sf) a
{
rf (oft > alpest) Posat5
J Sy
YVetinn Pos 3
j
Votd maint)
{,
int afl, 9,4, PSs
att (" Enter number of element \n»);
Slanf(" 7.4", ns
Print (" Enter id elemesb ".0)5
foy (i= 05 P< tH)
Lent ("Yd &liS);
1Pos = largest (A, )5
Paint fC" Lasqent eVd"y afas})+
Piatt (* Positions 4d", Past);
4
OutPut:
Enter. number & element:
Ss
Enter S tument af} 35
3s jo SO 60 15° ans} lo
Pos =3 Spx
Ledges = bo ese
Post bien = bp ALS] 60 [> bosgest::
ams
Searching:
, Peoteys of Finding a Parldley
tte 15 Present ta Ladge amount Of dats Called
Seaxehirg,
The dwo Seas. ding teint Pues ake
he Lineay Seaxch:
L (inaxy SeaxchTAGE-17
“Program 2. C PeoGvam fo Pmelemedt Lfneay Search
AH include
fat btodtey Starch (tot Iéey , tok al tnt 0)
{
ft low, high, mid 5
loo 203 high =-45
while Clow <= high)
{ ee (loorhigh)fas
it (lee == amid.) “webiore mids
bey alm J)
Shige = = mid -15 J Seodch Left Part ¥/
rh (Key yatn'D)
Lee Feequt Part #/
5
Yebwen als
} ¥
Void mein )
‘4
Int n, afjol, key, Pos;
i Print (* Ente Number tf Clemenk ws
Seook(" 7.3", &2);“Print? (" Enter Cluments 2 AStending order”):
Glo (t205 £0544)
Stank (« fd", GattDs
Pent (" Enter element fo Seaveh \w");
Stonf(s ig", Gea);
Pos binary Seavch Ccey an);
fps -2-)
Paint £ ( Ytem not found ns
else s
Print (" Them founaad thd st fen", FeS)3
3 i
OutPot!
Entey rumber of Clemeaks
bl Clumends 10 acrndiag order
lo 19 Qo as
Enter item £0 be. Seaxched-
Is
Them found at 3 fasion:
Dis advectese.
fy Ligt of dlenenb bo be Sorted anvetl(PTQE- I>
“Rogvamh! C- Progen to Intlement Bubbie Sort
teint bo Sort the dlemeak of ani.
Hinclude LStd!o- >
Void bubbiesort (Pot alt, nt n)
{ :
tnt 1, of, tue;
for (4= [ft teao P44)
ford deo 5 den-15 GH)
ws
'# Gli] wali _
temps? a LSI;
QLsJ= afd;
ALFHI = Lemes
c
bo?
\e'd main cd
int aL23 7, 0 5
1 PREC Entor owe bur of Plems \wny
Sook" 4" ha);
Pant tl" ovis this fo Sovt \nn):
: fy (te05 fen35 fH)}
Stont (“.4", baltd);
3
Petat tC" before Sovt \n 2)
for (iso3 Pens T44)
Rintl(“ 4d", ALIS
q
bubbre Sot (a, n G
Peinbe (« Aftey Sort \w%);
for (iz03 Po 144)
{ Ss
Rite" Jd", ats);
aS
OutPur!
| Enter Numer Gf items!
s|
Enter Cheers fo Sort
WO SS Sas ce
Before Sovt ~
foe os is
After Sort
gs 383 Cl
arAGgE-16
“Bro grarmtng Ecorse!
Too Dimensinnad ov Muli Dimensional Avwaifs » |
CProgvam bo odd hwo mabiGs: |
Toclude XStd¥0-n> :
Vord verd (int ZI L105 , fat om, tat M)
int ?, a
foe (420 iigm 5 t44)
fr (d205 G
ee
String Delemiter ~
“The String Veaiable & always
declared a an array of Chavackers -
Sota !
Chay Stving name] stxe])
The Payamettr Size determines total
Number Of chavackers in the Staivg ame »Examele!
Chay Cty fro} 5
Char Name {2s I;
Snitializing o. Stetags:
TaoHali lation in & Procers of assigning.
Valus to a Variable befive doing maniPulation -
* Diitall eq Chavacker by Chavacter
*x “PaeHfal fad tiodesbat om
* —— Without Si Le Sret: fred
* Taibeli Lotion with a Sig.
Tnitiad’Zing Chavacter by chevacker'
Chay OLI= fw Tue ye ys
He 6 memo] locations axe allocates
Woanging fom Obs
! a >Lv[T
0
v [elefR]
as
AS
The ASCII Vals aq the. Chavachect
f vor be Store in the memory beesPartial Initial? Zakion”
TF the Number GY chavackrs fo be
intHalitel dg Leys than the Sie Of coevay , then
Charachers Stoved SeQuentially from Left be
Right -
Char @abel={'c'‘o CLAVE Geb
olcJo}s[efeTs] eTale [E1S]= Johofs)
S&F 84
The blanc lots auto rn roakically Filed with
NolLL Chavackers ‘ \O'
Formatted Oude funcPion'
| The eutpat fanction Pink) & Usk
ko disflay | Prink the String . The (onverSiow
Cod. /Forenak Seti free Udeb oS fo Pont
the Sbiry e Chawackers -
Exangle *
| Chay a Lids
| : Slonf (“ se oye
Peinte ("5") a);
{
" Rink the Charecker$ Le Jour 04 Chavackeys
On to the monitos.c FAGE-20
Excamele Reo yarn:
Hinclude
fPinclude KS hy
Votd matnc)
{
Chay wordi fI9J, ovrd as 5
Patol Enter textt \n);
Slanf [£5 45", wordl, word 2);
“Rite word | 2388 "word !);
Printf(" \n wood a= ps", Wed;
Jetcho ;
Oust Pat '
Entes feet
WEL mE.
| VTUBELGAM
Loord| = WEL@meE
Word a= UT BELGAUM:
tyooed | bE L]c|e |afelye Ty
oO
eae
wooed (VT v]B
oo! 2
bl he? PT
FE 70 i 11S 7G
ey]
wlFetsc) + Cunformalted tnd fuach os) .
To ead Sequence of Characters for
én between and Stove
kKeyBoord With SPaceds
fs) funcktor
tem fa Memory loltatios J
do VSS
Syntore Gees Cot);
+ <3
Stig Vaitable -
Reb Shing of Characters Fe Key bontrd
AU Sex Presses Enter Keg".
“Rakes (Dt (unfoermedtel Out Pect Runckion)
Te distlay tre Stivg % Charvacker
“6 hae OutPt Slreen RAsSO fan hiow iin VSed-
Synbor'! Pats (Sbs)s
Ny
Sbrtng NaRiable .
“The farck fon di-selays all the Chavackers
Stored te Variable “Sb8" BU, £6 en Counters
AMSLL Chavacter ' \O! .tAGE-2)
Example Progam:
Fhinclude
include < string. pS
Void meint)
¢ Chay StrfosT;
Ges (St; inne ABC <1 (Press ets)
y
Res (stv); J/ouded A BC
j
7 ie -
Advantages &
Eahy to user Unformatlel Flo Punckions »
* A Singles} sequen le 6 Chavackers Gabe
wed easily or displayed easily .
Drsodvadboes
& Th & nok Posstole fo ved! Rint dons other
dete Crcewt Characters Ouly , ie, not
Posstble £o Print Inkagers, Ploakiog Numbers
aa To over Gene Ke above Roblem tne
£ focematted Ze fiunchions Unik: “Fetath and
Slan€()Skeing Mani PLation Funckions ‘-
The Vowtew String man'Pulaben fanckow
SuPer bel In C Longuage ate -
x Strlen (St) — Rebus the length 2 Soog Str.
o€ StwcPy (dest, Svc) — CoP toe Source String Sve
to destination String dest
# Sten cry (dest, Se,n) - Copies ak neSt 1 Chaactdt
Of Sowrcerbbirg Src to
destination Steing dest
Strat (Stn, stra) — ARPind Shing Str, to Str)
Shen lak (Str Stra, 0)= APPEndl Fiest n Chavackers
Of Steing Stra to Sts
& Stem (Stwi , Sts2) - ComPare two Sbirys Sty foe,
* Steve (Ste, Sbe 2) - Finds the first OCuvenle Of
Steinga in shang SI
Stuhr (Str, ¢) - Eland the Sterg Ste for the first
; © Charente Of Chavacker C
# Ste lo (Ste) - Greet the Stebag Ske fo lower Case
# Sty Wr (St) ~ Conveth the Stig st 2 Ufpey fase
Stywev (sex) - “Reverses the String Str
+ Sheychy (Stv, 6) Finds Last oCluven ce Character
Cc mm Sterg SHO
SeasTAGE- 20
Strlen (Se) — Sbsog Leogie
The funckion wetuens the Levgta y the
String sty, ft Conds all the Chavacters
Unttl ‘\0' Ona sobens tte total Leng the
Exnbor' Sat Stren (Chey st);
Exame |e!
fh include
Pin clube Xserrg. “
\loid maine) | Y :
Chow = t J=“LaxsHmana”™
Pande" Leagins /d", Ste By
,
Guts:
| Legit = 9:
Proglam: C- Progam Using USerdeftined Fanckto™
my-S tele)
1 fEinclude LS tdio- o>
' Hinclule CSERS-h7
Int my_Strlen (Char st3)
if
one
tisa 10svohsle (s£tJ 1 = 10") tH;
wluyn 75
4
Void maint)
Chay Sf2sT5
Pat 75
| Print t (" Enter the Seeing \n");
i ets (85
Ps my_Stelen(S) 3
} Patt (" Lengte = hd "ES
Strcry (dest Sec) — Sting OFA
The fanckion Strcey Cortes the Gateds
Of Sofuwce Stig svc bo destination SO n9
dest Incholing ‘\o’ , Here the Site
destinabren Shing Khonld be Greater ov Quod
to the Sourle Sterg -
Siniox
Stxcey (Chav destt I, Chav svt}TAbe-23
Examole Pinclusle X
Hin clude Number Of by ts Lobe GPicd £0
dlesti nation Stig
Sri > Source Strny
| cleat —r destination String.
the fanckton Strncey CoP! 1 Characters
Soom Source Sting be dein ation String
arf Sourle Strg ee tan 1, Cube
Shing j es Opied bo destinoh & -
| att Sourie Stig t more than 1, then
only nN Chavacters Copitcd £0 datinabkeExample!
Chor Ste Lod;
Chay Sto feJ= “4eco";
Strowey (Ste), Ste2, Sizerp (St) ;
Before ey elution
oT =
Aflee cae Stencey
YAGE-ay
Sty {2 |?
resale so Gls [eeP PR)
=
(ser AlB c|p \o |\o. RS vhs} stale Jo )\e] SE
Oe Se ee ele lel? |
Progrum'tnciase clara
Hi nclade & String. h>
Void main i>
{
Chay SLIST= “ WELwome To's
J Cher Sp SiJ= yes";
Pat den §
len'= Strlen (5);
Stroy (45163 + len, bg [e3)5
Sten ceg (ESLET, Si, Len);
PAM" Resulk 5", 8);
g be)Sthrat (61,52) — Shing Conlatenake \-
SYtny |
” Stecat (Char SL Chay $203) 5
S| - first Shing
Sy = Selond Shiny
The funckton Strat Pies a
to tne enol OF stig Si
werlated by
the delimit of Si Qo) - os :
1 pt
| Brvgt Charncher Of S2- The Bite % S)
cote ee
Chavackers OF Sa
Examine’
Hiaclude s
Hinchde
Void reine)
{ Chal: sg pel="AecD"s S\falelcfepe]? 2p Pp
a. ~.rCr—CsCsCis 0123 Garten)
| TE (strlen (5) 4+ Steen (sya stegesy ,
Paint #(" Eror Gamt onthe");
oe lon@tratd SHS
ctut (6,5; s, GE [eT bly olelM,
i! Leb Telsiek
Void my_stwcat (Chey Stuf J, Char Steal J)
20) J:
lohgle (Sto LIF ='\o') F445
fro;
while (steal GJd= v0 :
Ste Lia: Sb fu;
% s
Ste LAY Non,
Me meint ) :
{ came
Chay Sh, [aeJ= “ WELOME" S
Char Straws: " TovTu";
mY_Stecat (Sri, St2);
tat C* Con Grats Sky "D5
Prtatf (" 7.5", StS
fySten cat (s, 1S) n) ie Stag Number Conbtinal,
SYorax!
Stra cat (Char Sil IY, Chey SII, tet 0);
~ first Sting
Sy~ Selond Shing
= Mumberog Chatackers 06 Sting Sa
bo be Gn catinatis
TL the leg ta rg Stxiag SQ +o lens than n
than funcetow (pre entive Shing Sa to
ens Sr . :
bt the delemete’ OF Shang S, to wPh bed
With Sting So” first Chavacter
| Brxcelut on iefure Sten Cat
wb PE PP) satu ]y]s Jo Jefe
SAEs Fg Cy ey are
si fv
oO 1
st!
After Oxeusion Sten at (Si,S2, 2;
Si [v]r jula y|s ss)
Care (9 Get
Hot BS Chavacters are Gpicd fom
Syins Sq bo Shing Si atte exch 2G S).IAGE-26
a Stvcmp (Si,S2) = SHIN ComPare
Eywray |
fot Stromp(Char Sif T, thar Sat);
S\- Levee Sting
Sr- Setwond Shy
The funckion Streme ComPares te 0
Stings - ComPexs sion Start from Stoaking
Chavackor Of the Shing
> Tf two Stings ae Sefual webrns O
| a eS Geeater Lean Sq, Me Value volurned
| TES, be depen attidins Negalive Val
a
C= Progfam® to PmPlement Sting ComPoar SO"
Wing may. Strimp Pancho:
Lb enclude LStdio he
fat my-steme ( Chay SILI, char sol)
ink feos
while (sif==SafiJ)
{ of (siiid == '\0) bran;
THs
vehurn SLg- Salil,Void = main’ )
{
Chey SiLJ=“ Vu";
Cher Sofjy= BELGavm;
int diffs
diff = my_ Strme(Si,S2);
Sf (ditf == 0)
Rint (7 Seg", 5 Sa):
the lf (diff +o) r
Pintf ("SS AS", Si, Se);
BCL Mitch
Ube
Printf(" MS LS", Si,S2)s
Working of function MY_-Stecm? ()
/ > Leo Pf Sy eSo
/ | —> Positive Pf GY >Sy
> Nygabive ES < SotAGE-QF
Strevev (Str) - Sting woerSe
Synlioy |
Void Stevev (Char Strf3) ;
> Ste Tr Ses
The fanction yeverses all the Chavacters
nthe Sting Str exceet ~\0 % OvIf inal Shing
io Lost . ‘
Examele! >
Hhincluce
Chey Ste[J= “ ELwme ";
| Sterev (Ste);
Pratt ( Revise, = /S", Sh);
\ :
, Oukhut’
Revise = EMOCLEW!
‘
The Strrevd So Inbuilt funcklon deffacel
“Sa Stig headdftle“Progian C Progtam to fmPlemenk Stray reveise
Using _USer definest fun Lkion:
FeinClise Live hy
Yoioclade mMax?mum Len of
on Numindiag SHS ° "
Sbinge.
Cher afst[22I;
> S to tne declaration ind! che teat
S Student noes Con be Stover:
> Qo radiate thot Sh name oo
atmo St” Qo Chagerbors
Tiitvalitaton |
Chad ofS = £.
“WELwomeE",
10.
“TOS
“BanhAtRe ‘
j “BELGAUM”
va
ThE Unmeds Gale wed anch atlerted
Soh tre Loo? Stained a4 »
| fox (te 0 Peep 3°41)
4
SOnf ('% Sty ali D:
i}“The Atay o String Valuca are Pinte as
for ( foo 7 reo 2 PH)
¢ Ref (rs, afl
h.
£2,FUNCTIONS. Pie-29
funckPons 89 C
A ladge Propham Can be divides fro
Small Preles Called modules , ach moolule
also Caled oO fanckion The funckions
O82 Clumfred tnto boo Ways
Funct ons -
Libvary / Se User efgred Fancbiont
Pred fined PunckYons (Reogfarerned olepined
Ext Gt? cfamck' ons) /
Rwl d; Ext Adal. Liat a, at b) 5
Lébvahy Rancilio |
The Collection Of Vadlous -fumchiows
“Petiforen Stondord fabk ond Fre defined
tasks; the funckiow LOW ttn by the:
Compiles manmfac barers GUL Ubovoduy
Sumeki ows .
{ Excomeles
Powlcy) — WwenPutio 24
: “Spel — ComPubo Shale wot Of X
t Piatt - Used bo Peatdala on outtat
SFO - To ead dade fropa ey boat -USex defined Functions !
The funcktonk orilter by the Programmers :
bo do tee Stecific task Callid USex definct
| aloo Glued Po Giverny” definedt
funchions -
Excamole'- Hinclude
\ord oatl) A vser defined
R Punch on]
fat 4, b, Sums
Pid £(* entrar;
Stomp (187.5 "Ge ODS
SumaOtle 5
Peak ( yd", Sud;
WUbwkn; ft webutin Combi fo mainly
}
| Vford man’s
{
add C5
weluday Arsthida Contato OS */
' 4
Not DEve idiow Stat, Prom main
2) Fan (blo Gad) do Tavoxest & Combet
trowfercd Lorn mains to addlO|
:
|
‘FAGE-Z30
Ekemen of Sr defi ntd Rin Cblona
Ly Function depratton
Ly Function Gall
lL, Fanctton declaration
Fanction deftatiton
The Program modube that t oritin zo
Achieve a SCLC tasKc Mo Gala funchion
definttion
Stoton’ wie PedLam Fenchfone
, pa é ( cas) eee
decldation (Pot; |
Functow
Body
SY Gretdoble Parts
cS
welurn Stakemet;
y
eee
tyre a dakatyPe tab, float, Char, ord , couble, uc
froime ~y function name «
Examele *
1 douste agdCdouble m,dousle 2)
{ dbuble Sum;
Sums mtn5
Behn Sens“functPon Declatatron/ Roto tyre \
The Pot finchions dethring
before they are Used (or Gl) 3S fanch'on-
‘Rrototyee | Tk to also (abled Panchen declSabion ;
Sywtae!
tyre Frame (type Fi. tye Pay styre 2)s
4
Framer int aad (fat ap bat 8);
Void Sub Links, Pat ¥);
yee = dats tyes Unstt, Flee, double, Yord,
Brame - functions ome
PB Pn stb of Pada Eber $ Ser rohd by
_&
Comme.
once th fanckiow do defined, @thas
to be Calg Zo achieve tne fask. The
meted. of Cabling function to achive a
Ceelefec fasK let function Coll
Beatle Void maine)
ee
\ ses = ada (lo, 20);
4 L Arsqum ete ©
Kunchion Cl.
—TFunction Pavamaters: (4e-S1
The Vattables defined Pathe funckton
And the aNuments ta the function othe
Coblid. Pavam bs:
Fun chen Pahametees
Formal Actual
Poxamettrs Pavrametise:
Powel Faramelivs! 2
The Vartableadepinedl in the funckion
header of funckioicdefinition adhe Callest -
Foyenal Paevamn apis The forme Paden tis
ake aloo Cablid dummy Pararnettrs The
Paramers Veletves date toom actual Rramelers
etal Parameis
The Wadiables that awe used When
G fanckion to Ua ov Invoked ate Colles!
Ochtal PevemekerS The dats tronkferveol
fo tte fanckiows USing acral Paver ekers .
f The type af date Omd Number Of flamebars
"Should match for formal fathual Favamebsrs
i|
E yample > Hfnclude 2
: double alt (Housie x 1 dowble “¥}
{ wdiaxn octy ; Formal
y Pavamettrs
Noid mats ()
{ Obuble a,b, wes;
Pintf(" ect ab \n);
Sled ("7 LEY LE", & &b).
wees add ((a)! Be
\ Vetigur! ge Aimar
Categories of 4 OF Frc kros |
The function oke Cabigor’ Zook
ae om Wttuiin Value by the Punckton €
FeSamn tts alleptesl -
OR Tanchtons voit 00 Ruramilihe Fro vette Values
ab Funchiom With no Rdamebas And with vider
| Velmes
Je Funchtons Witt Paromita € 70 webain values .
% Finckons With Favamitae § with ytd
He AFAGE- 32
Fraanctlons wrth No Pavamebars & No vetion Valu’
he fanckiom ade wrth No Pavamdas.
Heve Hewe fo 0 dodo teonshex bebdeen Calling
and Called fenckion y Calling funcbiow Connst
urd ony Values & Called fom for Cannot
Yeleive Ong Values
Example}
Hinclude Noid adel)
Void odhl); i int Ob, C7
Votd mata Paeif( ents a/b \n");
“we Slo ("4d Ud", Ga,8b);
adh LIS Coat;
fina = Routt ("Same hd", C);
TT etter 5
ls j
Fanckions Lott, Fadameters & No -
Utd ada (tak @, fat 6)5
\pid main (> Void Cite, ta)
{ nN
ee 1S tab Suen
: 5
Pant enka rane dy / on
f fame a+b)
Slaaf ("rd hd" Gem, a); if Rath’ Some Gur);
aad (m, a5 ----* Shans “
Seton 5 KT S 4
iy x
Fanchtons istth NoPaxamdis & with velo Volucs'-
These & 0 data teowsfer Fron Call
I
Ranckien 40 Caller function, But the deka
18 teonbferced from Coble fonction fp te
Calling. i
» When Be Contol te brane fnered. £0
Lie Cabld function, the Values ane Yeaok
ave aged & Welk do Stored ta C&
ye Value Of C fe waned -TAGE- 33
Evontle >
include
ace a add
Void mainl) a tak 0,6, 05
oak Cs i Pint" eatin A b\nr)- |
ae Start yaid", ahs); |
Coaddlls wa. | C= ath;
Paatf(“ Same Kd", O; © sen e
Weta 5 y Joh cise 140
7 C Velie &/
j sé
Tunck’om Last Rrameters € ott “vekern Values’
Hele, the dala transfer between the
alltng fancbion tnd tre Called furch’on L
done . when Palumebers are Pomed, the
Called funcklon Welet ves the Valles from -tBe
| Calling fanctiom *
pohen funcktor vues 2 Value,
the Calling funchiow Cam we CG ve Value fron
Eee Called fnct orExamele e
thin clude
fat ada (tnt a, tat &);
Vord main (>
{ ee jet add(tat a, tat b)
Rist" entic mon; ff tak C3
Seal l td L3" 4nha), ee
a SS _tvebian Ce
C= aad (m, Ope & y .
Petal ( Sm = Pd 0;
CHidw 5
{ -
Argurn _ Pabsr y e
| The Biummenk ae Parseol
to the fence in two Loans
Ll, Call by Refevence:YAGE-34
Coll By Value
The Values of achual Pakam ettrs
OAe Pied Fato formal Pitameters, here.
Lyenal Pavameers has why the Cory og
Actual Payamuers. Pf tee Valu Chenged
In the Called functor, then thé achral
Pav om bors uorll not be Change oh -
Examele! .
Hinclude Létdto- i> ge? Foreal Barwon thde
Votd. Soar (tak Paint Y) ~
{ Pat bomb : .
tomes ‘Pag Yy=loy
P=W5 - a7
Gag ete
| Verd main)
Int 20, Ys
de105 Yaass
| Svoae (x, 3-7 AC
Piate(« acand Ye %d" 25 4);
Bubfict
Q=10 b=2o0-
fal. Paden etsColl ey Reference '
Loken the function & Calleol, the addres
CL actual Favameters ore Sent -
k The formal Palamettrs Should be
dethrel os Portas fn CoMed fnchion wrth
Game, dota gre ad actual Payamelors . Ph
ve the addwess oY actual Falameters
ake Copted into formal ‘Favameliks Using
three adel Valu A achual Fara eteas
abo Gabe Chargect . >
Example '- :
FFinclude . a Foren.
Void Swar(int ¥Rprnt *Y)
Cte tee xe
temp = RP:
PH KEYS
y= temP;
Padaroo”
h
Pd = maint)
int @, bs
| Q=]o5 bao;
Sap (a, Gb); > Actuoh PaSarvilils
» Peaif{('annd b/d", a 6);
} oultick
Q=20 b=10°age -35
Lotatton Of Funckfons!
The funckiow Canbe olegiach ia .
\adious Places tn Same file or défgevest files.
The functton lolations Con be Aone in three
di ffevek Veaons «
Ly Ranchtenstmenedliataly after #inclde
Ly Funckiows agtey main ) fenck or -
Ly Tincbong tr SeRetade fetes
Funchrens van mreclionely aster thindude & fidepine’.
> The chive finchton deptartion Conbiating
of Runchenshiealer &funcbien bedy dis Patel.
ak begining o¢ file fromecl’ toly after tPinchaok
+ The funckron Proto tyre Com oe Cro’ beck :
aun L) -
$f famchfon fo definet before”
f Hein cule < — _
1 HE dene
U) Ean kon Prototyrs
J] Funckion DY g nitfows
i ‘ J} Meinl) func Ef ou
peeExamole !
Hinclue
Votd Suave Chat x); /x Rinction Prototyee+/
Void Stance Cink 9) fe defitht one
Pout tC" Stowe = ed", (tad):
Void mainc [# mute Lunch on */
int as :
Fanté (% tata "Ye os
SOd (ry ds -
Stuoee (ad;
j .
S
Function ALLE ynatnU) i
~y The funckon Prototype: Should be. ttn
formedtasely after Finca es - :
~ The maint) funchon Will be Lortten
followed. by All Suc funcfoun defini Hons -
ee
I fonction Peototyres |
If rein function |
a0 i
He funchion definit ous |
1
r .
‘
a
‘
{
‘
(
||
PAGE ~36
Examele >
—Hiacude
Void Sduare (tat P)s /3e Function Prototyre/
ie eo J roctn Lenco)
a
Pratl Centr x 5
Sey L Ld" &XY;
Suave. Cx) 5
Void Sivane (Fat a J Fasichion depinss' owt /
ag
Pantf(* Yel", Pep);
5 &
Funckions fa SePevak Files!
> Lote all funck*on Pro totyees Promedlielily next
to # include SHdlefines
> Lotte matin) funchionr
Hr define all Uachdeftncel funchigun Si sera fles
ea.
T phintludes he
‘ ( '
| hao don Peototgees | '
(
t
A i
" meio func on: ;
; ;Example’
file 1. ¢
Hinclule
Votd Sub( fat x, Pat Y); MW Fanckfon
Void mate frre, fore UY
{ Pat Yb:
Prntt{(" ents a,b");
Son t(" fad", Ga, 8);
Sub(a, b); & :
5 ' se
Filed. ¢
Voed Sub (ing ‘Ne, tat Y) [edge
{ depiction xf
tat Cs
| c= x-y5
} Piaf 74", €):
Notes Heke, the main(s ProGfam i4 fn One fle
Bel other functions are defrel Pn another
frle.; they axe ComPtleat Sereyetoly | Ths wee
Leprosy funchions ate used:‘ReCurssion * M4ES#
AL ReGuvssten Lo a methool Of Solving
Jee Problem Lohere the Solubon to a Roblen
depends on Soldiows fe Smoller Pabten (es
8 He Lome Problem. “The welarste fncbon
Le a. funchiow Hak Calls *belf during cecsion:
“Tivo Ways & ela ssion
> Divect veGaston
L Todi rect YeCUAS on,
Direct yeussctons
A welubieve funckion Hot Invokes
‘taf L Sait to have di vect Yelaeston
Examtle’ tak bok Cenk n) 4
Lee Cy ezo) web 1
yebere eft (nds |
\ x -
Godveck YeGawston'
A funch’on which Comtaias Call £0
Qnothey funckron: lobe ch en tuen Calls andther
Meee and Soon & Call ogatn Livst funtion
Cal ‘Indivect Keluvsion -Bowe 6 8, a.
a “a bo 30
(
¢
:)
| a O: tre: -
“Reo glaromias Examples for Relaxssten
O Com: Factor ek-of 1 -
Ms] thas as -
nls | ML = n¥@1)! _Sibuwise
por the asave defini Hom Lonchiom
for fac korvtal 1S WH a4
th n=o
| FO) = i & Fln-) ofhew'se.
Fanckion .
gat fact (tat ”)
of TE (n ==0) Webs 1
Vern ne fact(n-)3 A hen NOW
5ete mack yf
“PReoqram |:
C - Pro fam bo Comite Binomial Co- YE Cot
Nes nt f(a: * 4)
Hinclude
fink fact Ctat 0)
4 Tf (ne=0) wed 1;
thorn nie fact (n-!);
Void maint)
{ int NGS
Flock weal
Rave entre “3
Slog 4", 49;
| Pratt (" cakes x");
Stand O° Ld sho;
Yuk = fact Cm) / (fact (n-v) ¥ ct ls);
Pith" Yd Chad = Sid", 0, ¥, vee);
j
OutPut
¢ Enta ot 6
Cre ve Ss
6¢3 = 20 -Roxfan-2!
C- Progen Lo find Sum of ane elemento”
“using Reta stor
#Hincde KStdio-h>
float Fun (fiat aft Fiat 0)
{ tf (nee-1) yebdn 05
Faun (a,n1) + afl;
j .
Void maint) oe
< ° °
ie ali
Fat afists Sum 5
Biatf (" Babs dumber Of elum enbs s
Soot (vyd" 4);
Rantf(" Eater elrnedk ") 5
fir(te03 tens PH)
Stamf(* fis", GOLD);
‘ a Fun (a, o-)5
RIAL ( Resulk =f", Sum) 5
4“Reofean-3! Oecd
C- Progam #0 Comic factorial bf Oumbory
Luving yelurssPon : .
Hera clude
gat fact Gat a)
4 ep (eco) ~wehdn I;
yearn Nefact (o-1);
}
Nod rain a
{, oe
int ON, seb ss
Rial {" enban »;
Stanf ("sta") 4);
youl P fact (n);
Rent (" 7.6", woulk);
ip
{3s
Limitations 2 Returston} (Advantage)
> eiwsive definttfon Can be eatiy bonslatid
1 fnto webasi WE Lunch’ om -
~> Cleaver & Simelev VALS? ons 4 elusive
. Lancktons Can be Cees -
I Many fauncbom ate eanitr bo foplement
rseconcivdy & efsiCed -DiS advedage Y Tecrssion
> Stove funcklon & Callel weatedly tt
takes Move Lime to exett,
~y ExecHon vo Vely Slow GmRred to
ottey Pevodive Counter Rat
a Consumes Lot of memory When fone fon
do Called -
Pre Faun - ;
pane to Cvaluat Sum yf Dakawal Num bows -
Hinclude [
ink Fun (tat 0) e
th (nee -D Rb 05
svchurn 42Fun(o-t)5
4
Void main C)
ink 9, Sek
Poth ( ent 0):
1 SOf (dG:
ywuult > Fux Cn);
Roatf (« Rowik= fd" yout);