0 ratings0% found this document useful (0 votes) 93 views26 pagesC Arrays and Strings
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
Arrays
ae
pray 2 Array %c a collectfon of Snftay elements oy
homogenmus elements. there ave ~three types Of ayrays |
A. Fogle dimenfonal array (ov) one—dtmenSonal asay
a. dwo d’mencfonal array
B+ mutt? d?mensfonal array .
4. one—dimen§onal array +
AQ array wits one cubsex?ptCe 3) % Known ae
one dfmenfonal array. 94 ¢ used ~to vead the Yows
only .
symtar >
—_—
datatype anayname Letze] 5 |
€X% Tot atB]s
nvtalfaing_one-dimentfonal ary
Ant AES] = Plo. 20; 30,U0 50h Deel Ateneo
In memory H with be Stored ae Lrolao]se] Ho] 50}-ravvay |
Ale) at) a(x] a(s} afuy tements
Tarray address .
AWA Pp W read any 5 elements L print -them i
Ry se Include ”
mm 2) 3
Scanned with CamScanner7 2 WAP to print Sum of array Bf clements,
HETnclude 4 L4d¥o.hy
matnc >
&
Ent ate? (SUM=0 5
Prine Senter 1 array etemente” x
foreieo 5225 4 M49
{
bean? pa", harry); , i
3
& f +
zh for Pao 5 eos h4)
ve £
| ia Bet Hye ai”, ATED) D- Sum = cumsa(t] .
)
|
|
rial? Cpacumer.a”
}
3. WAP Ho gm mavinum and owfara elecheuds
fran array.
» sum)
HP frclude ‘eetd¥o ns
E & aomafnc )
a
*
1
vil
a
ae ;
= int alg) 9 MAL nn 7
j Prine enter eleenents”)«
forcfeo, fess 4) 1 a
$ mils airy my
SeanP Ce’ 4", atk))3
} biw
forcieos he: ty)” q
£ 4
Peo! Dag? :
Marte mid =e(o) ;
a # Caw) > mar)
mar zatils
‘ Scanned with CamScanner# Cect?)-2mfn))
minsalt)s
Pane (mart = %d") mat) 4
petal (ans nas ako) 5
y
we two0 a d?mensfonal _ arvay 3
nas two dimensforal
tan, arrat atray of array fe know
tet one
array» St Xe aelned Wish po cubcerfps the tf
one. wndfcates wlumns. PH can
Indicates us and second
be used +o yead -tables-
Syntar 2
datatype atayname tstae] (fae)
mw column s
4nt ats) fu) ;
ter)
Int AL3)wJ> Wrasuy ATE DER, LA roa hy
Sn orev -to enter characters or Names Pn -hyo dimenc?
—onal array % can be wethtion © aS.
et: char Nan) [w) 5 , 1
tony
‘
Char Mamefa)fu) = 18s! 3 i Pet Blom! tat prose
Ym Memory %H can be swced Ap, = Ac A
Afr i
RL oy PR
a we 3 -too dimento nal array! +0 Wtfalkze Uo to
_usnq tuo ww and & columns.
ant a Le’ .
ue ~ BEng susp, 86.9 8. 9,1098-
tj2f2l[s\
éla{s jal]
>_——$__ ee 2 a
Scanned with CamScanner2, Loic * ?
= 2 ae ofo aer
-ftz r(f } Are” (io
a (3%) B (3. ;
40 Ww wo
CHO cai
for feo, fea) TD
$
| tortheos fas faa)
£ ;
eetyey) = atyJer) +6lrV1F) 4
$ ped Hoy
3
C= AIB = Bae 8
CYS Jealhy fepeberyeyy er” !
€[o} fo} = alo) to} + blo) (vo) = > 4
crty ef) = att) oF) birt)
Ctor i) = ato) (i) + ble Li] ~ 248
COIL} = 40900} +b[] Lo), = s49 x10
cO)b) = ab10) +b 0) O) 2, ude eta oi
SWAP for mat addin :
ah Include Astd¥o. h >
maine > aye OM 0 ;
z
int ats) (2), bE2)ge) scl8JLz) ,P
pari Cemer, 5 mati 94,
tor(fed 1 kgs 1%)
2
i 3 R34 Srey
’
scans Crd", SoS0G7)3
2
Scanned with CamScannerEe
paint? Center @ maiity") +
for cizo: Pray Pt)
Fortleo: hg 1344)
L
Sean Cy”, BbITSCTIDS
>
3
Patt Ca matita Pes
forleo, $231 M4)
£
dor eo; Fxas3+)
Leon Casa”, al) 5
;
Patt On" 5
PRALO B mate Falk ys
ov Cfeo | 9235 M4)!
feo £3 fay
PHONE Coa”, BERD) # |
“Pose fn eee ne
str eo: Teas Pa)
Forh=05 523544)
em 2 Olt) (27 sell) tT) 5
3
Py
pint Cac marie x aduhton 4"5
Aor (0. Pees Pye :
Scanned with CamScannerCe =.
fortfov fia “Paap
$
PHOLE Cn aa, ety ty),
}
prfineh Cyn") ¢
>
Marin multfpl?catvon togfe «
Tede; ah e b= (34 pax =f 2
34 oe
for 0: fegy eH la >]
forcfeo \ fea 5 fH
2 ,
Cte} i xo»
Aorck=0 | kee ‘ae
£
CALF} = ee (?j I) +actyre] ebtkI)s
a
7
P
COMET] = ceeqys] +a tILR ee le)eyy -
CLo}fo] = Clo]Lo) +e (0) to} x blo) [0]
2 0 +1 =S
clolo] ==
CHC) = B+ Colo} -al0Iv) x wliIC0)
= Btowgs 4
COON = CCI) +afod Cope btor()
= o+leeeg
CCL = clojtr) + Alo} tr} sr) (19
= Grae = go
Scanned with CamScanner(Co) = CCYfo} sal) LoyRblo} Cop
FOBT 2
cj fo) = COLO} aC Cr) KEE Fo) }
= US 4H 3-= (Shoe -Ug \
cout = ctyey 4a()(o}ebOI()
FOF BK EH 1
COI] =
CHI HOPI xe trIEe]
= IW 4UKe = 5D
WARP for mati? — mubt?plPartfon:
Ht Include cct+d¥o.h >
mafn ©)
Ft ataIa) bla} C2) cl} 2)4,FiK +
Pinte enter py mabitt”55
for (feo
$
forc$=0 5 $291 fr)
ont On Sd”, pany
3 4 '
a
Paintt Center: arate)
For cieos ¥ x5) Pd)
2
for (f:0) fun dpe)!
3
sorta g uctotty),
3 ; ;
4
Scanned with CamScanner
2%) See)
ar
PrIM LC” wy maha, 49h)
eid 1 Pray t+)
for Cfao! fray fay!
<
Print Osa”, att ati) ) 5,
id) :
3
Pia C\n"5
3
Print! OB mabey Paras
one V Pea RED cet _
Pr che ithe: Suny
oe Chsa”, beracrs),
Ba BMT ED i(ghl ¢ 287
Prtntt OY Vn"); a %
3
forct=o fxg 1B
3
for (feo 1 faoy Si)
wea JE sways eo "yh
£ pe = COPIED Hah ICKY RCENES):
| |
} oot. .
Print C° @ matyix muttiplttarton te \n9 2) |
tor (feo » faa! Papier ies
£
for feos feas Si)
&
\ Primt Ona", cdo |
La Betis ove: A
Scanned with CamScanner|
war for +rancpose | Maty?x.
4 Include gtdio. hy
main’ )
£
ft a 3903) , eta) 5 5
PIMELC enter a mahi)
for C4201 P23! P44)
3
for Cfeo \ fea: fat) |
& "
scant’ meq) BallIeyy)s
$
¥ eater p maria fn")
for cPeo , Pa3 sf)
5 is
forcfeo s 9434 I++)
£
prime Mead", att es)
3
PraiettC™ nd 5
$ i
prtat® Cprancpose 8¢ aNny;
for (feo, faa 3 Put)
3
for (feo 5 P23 5 SH
5 ;
Pate Onsd ", alfIlrps
Pint éC™ \n" Ds
3
j
2
Scanned with CamScannerWap to pint Ydentity mehix ,
ste frclude zaldio. hy
mMa%n¢ >
i
en
PAE C'Ratemfy matings (ay:
for
3
e053 mas gay oH
3
print? Cn");
,
St
Lin P for symmetfic mati?
aE Indude xctd?o.h>
maint » p
x
Yor atalta] teertay, 7,5 , Flag 20 5
pratt Center a malin":
tor Ceo shea) Py )
Se
tor ico ; Sea, Si)
x ;
scarh(%y
P
ae Comat % Wd;
Saceyeyy);
Scanned with CamScanner
=dora 0! 435 Fr)
i
© for C$0} F235 $4)
2
Pha C yaa” aticty:
painlt (\n%),
* "
or Feo FRea tay bl adiie
For cieo 5 $23 3 Ju4)
4fIG7 = oC37F7;
¥ shoe 2
3
phinlt C“transfore of a @s\n")
dor cfeo 5 P22 2TH
3
orcfeo + fess fry
2
ee Cr ad, cercpy:
Prinkt (an) +
or (i075 4233 Fut)
2 :
ctor C0 5dess fry)
£
FF Concvaesate ertaery)
Ftag=15
break:
3
3 i]
9 (flag==0) .
pas C'symmehife")5
;- C" not symmetrfe") j
a
Scanned with CamScannerry Muratmentonal array 4
An AYYAY Contes of — move than two subscript,
Ys known ac mulfdgmentional avray.
“LY otal toca):
F5 N0, 20}, PBo.uoyys 501 Gop, $20,803}, $240,100, Mo.
Won from nwltidvmensfonal avray.
AH Ynelude 2xidfo shy
maine >
2093}
Fn atate7 = 38 f00.20},850,40FP , $ErmiBoP $30.9},
FH AoWW0o} 110 12.07 FB
Wot TGiks
PRott C* mulfatmentfonal ave \n")
for (fe
= 2
dot Ci=0 5 furs ty)
$
for CKz0;
2
PRP Cea” aly y MeL
3
Fit t Cin">:
©: Seas TH)
KOS MH)
—
Scanned with CamScannerPERI NG vervays +0 tinekone | >
we can passthe svalueS of an ariay -fo a Puncteon
wih the name of the an aay Sn call? Png funetoon
use spectifed the rame of an, aay wWitkou Bay
Subscript -
WAP 4o fad she areninum, Clements, 9 an sry
using arrays 4p func#2on.
AE nude BA d?o hy
For kargesr (8b! al'1,8n)_n)?
Moin ¢ > be bhgk oa ‘ }
5 oo
Set ale] = Sto Sy 60) 4,803 4
bargest (a, 6):
ay
Sr barges}
5 q oat, tay
0 8, mars
fmat= alt);
Ne il
mary
Pott Omar ey” mar);
Scanned with CamScanneros
Seavching and Sorting =leelane es!
“Pere are a-ypes of avokiny
Se;
Stele
Hoecar Cot) Seauerbfal search
2. Binary Seavehing
fal
Hear or seaugantia :
° = ‘seauencfaliy
WE ave search ane ceavch ‘elements are
one by one
wits clemenls &n array), 94 tre Search
element! &s found. we dald the ehee Potifon of
eral @N Searth elemeny Sf the Search Clemens}
Ys not 4ouna_ me elemen) was na ens |
Won e SOY Wear search, CO) Senet |
te ToUude xctdfochy iv?
main >
é
Tot aio), 7
tLe
1, NG Search: vy
pims Center Ree op =rayy.
Scant C5", Lays
|
}
| PITT ( Senten element of can ayray'
| 4 C80 Foon a4
I 2 fe
} Sank ("4 44 dati).
|
neo i
Pane ¢ rie SEACH elemeng oy
| SOL beg gies ds
tor (feo + fens 4)
3
Scanned with CamScannerSf (Catt) = = Search)
PIMF Cd Fe present al postifon a ', Seayen a4t
ALE) = Flo ASE S160, Uygop
WF (fe=ny
PAF CO ceavch, clement net found’) +
1 +¥
Scanned with CamScanneri |
Ven oi ; .
«Binary seach é |
3
\ pil SIS kot Be ty eb
2
2 4 s 6
BSter 4 t me dad howd be, % sorted orev
SP a2 here Seaveh oF
Step ay SP the ceayoh clement = middle clemeat .
i “then Slop tre procece.. we Can fing. niidd le ctemas
| by Contedering the starting element Poon a¢ |
beqeo. and end = 6Cn-) |
MEd = beqtend 4g a
2 - 3 * |
rm °
Netep * -Hlere cearch Slement % nol equal to tne rrkasle
element: difae the fel nln wo parte
Fs lower bound and another f upper bound
| Steps? 9% search clement Ye lee than “the mmfelale
element tate flower bound. that &
seaych 2 middle
IF 2 2
beg=o |
end= md-l
= 34
| ae
med = begtend _ ob2
} “2 z &
step 62 now ~the middle element % 10. Search element
| (&. tleve the search elemen!
one
%& qreathen tne
middle. then ake -ine Upper hound thal fs
beg= m4t. and end -remaiad came.
searchy middle
IS >10
-— be = mid 2 iste
Scanned with CamScannery end= a
upper bound
vege afin
Sab
eed er
mfa = begtend ata 4 |
2 3 *2FA
step = Nou the fiddle clement Qe Is. Which % or
Searth clement . we found ts at —the positon 9,
“then Slop the prpcess-
4A WA P fox nay search.
at Tnclude xud?o.h >
matin ¢ 9
Wnt array Puno] fret, Jast s mRadle . fn. Search;
Pim4 (enter ze of aay") |"
ScangCro, 4", tn);
Pring.e C Senter array elemels In sorted wider"):
Pore by, fen: fa)
£ igs
Stank Cy. favraytty);
Prt? ( ember search tem
scangc’ s ," ent");
Cx) 2 ene
» Lgearch
Seat 20 je
last =n~1; (he
middle = (Pad 4 tasiy/, »
ve Cheat fact)
EE Cary
3 8Y UmFadtey
SWAP)
Neem cee
No Siszgl i
Va Be lnwars a6 FH
No.
Vip 2.504, Sy 4
[soap
'24 5 @ 4
Scanned with CamScannerr ae _
—fassm 6
yo gause &
Ser: Here the ffl element femiphed Vth, Secon
element, $ -the rst element fs qreerter than-the Second]
element . Then, swap both -the element.) SP “the ret
|
|
|
|
|
element gaa. % lees than second clement - then “Het
will no swap. 4
Step 2 2 now, abe second element Compavedl wry |
“ral element oy™ “$4 9° then ‘ews both second
and Wid elements. 52 ne second element RS Lese-than
THE HY elements. then there will be No Swap
Continue ~the process) uns?’ You’ ged the forges, |
elemer} Ym ~he tac! posPfon! ; |
Step 22 Conifnue step 4, iid hep a Urelfll You get
The Second Jarges! clement I) Lact fecond Postion
Which compleates pact a. : !
BAep M* ~we giprocene a comPrued Umit foie com plea
~e all ~he Pupece Pree, com Sorted elements.
from Athe above etample we have seven element
| ard she Passes “shoals be &,
4. WAP tor Bubble sort
} 3e Include KetdPo. h>
\ maine 7 -
& —
Wm 9,7, asit6} Nitemps /
Prine enter aus of ayyay"
Scant (“a ons
Print ( “enter elements”):
Dd for (Ico 4 Tent fee)
Scanned with CamScannerhb 2 Ny nN
stand Ca"; Barr(7]) 5
¥ ‘
fora s fans 44)
fot C03 Sun%5 S44)
ia
Corti santyiy)
z
emp = atny 5
off) = aty, v;
of fuy - timp ; ait
3
2 ¢ tiey
¥
forcicos Pans ty4)
x
ai Ca") antty)s
3
Stings
she grup of chavacters ¥e known As shyfhg. cor)
Characters ayvay tefoun AS sting.
Suntan? datatype © “sng name Csf2e) ; a
chay name tae} = Style de og Bt
ton .
char name (to) = “vaaq” :
(or)
Char name { J = C welcome + class’):
“the Af Perence between aay and Stings 8 that %
array . What cver tne Gye we take thal much clemeufs
Can be decleved. Where as % siRag AMY we also
eondey a null character tp fhe Stae of 9 array.
Scanned with CamScannera is denbied as\e % 9 upg
ge character ¢
end of. the Stofng. MH 4c alto know
aid Yepreser| the
AS null terminator.
Note 3 ri |
KE for each and every sbifag + fll erminate UM |
Null chayacter.
HELE Suppose we have “3 chavacters dor a hing
“Then the cfye will be “g’
Sitios, Spat /ovtput Lnetfon:
Prine 9, scanPer, getec y, putse> ave ane Shing
Sop, dutp — dunctfone. i f
—the format spectffey br tne siring Fs % |
WAP +0 vead your Bnd pitt! them.
Ae Pnulude 2 stdfo. hy
maine >
z
chay name {to};
PHO Cent ex your nawe")
Scant Cm" hale) 5
pant Cys", names
i WAP +o enter yur name and piint taen, wing
| BED on “ ges’ ond pals.
Geinghde sting leng!>,
we
simlenC J=e. Stitag in tenth!
sivemp C) > shifng compiler
senemp( Jo shag n compiler ©
3
4
B. sttcat C 2 Shing cancatfnatfon
6. erect C > sting n cancalfhation
5 serery CD-9 shRog copy.
g.
oe
SHEP) S ctring 1m copy.
Sttlenc)
a
BK uced ~p court she te of tre Stvtng ach
=ngq cull character.) |
WaP for ching length (eee)
AE Yndude
smoint.)
chat str dt J = “fon to clade”!
Pat Cope length of Syd Ys", aylen(sert)) s
3
2. Skenlen 4
Skenlen,
S+8e used 40 count “the vy chavactere fn a shitng
XCludPng null character.
WAP Por strlen.
H Mclude
ab Andlude caring . hy
matac ») '
% rai
char siv4 PJ + Welcome ~to class: ‘
char swal)= “ ece-g"s 5;
BE otrtot COAT, Strads “
PRL mE dal pat MS’. Strt) +
6 Shencat Ct 94 % used. to -rake first n Characters
H stra and ton catnated 0, Strd-
Ware for Strneat": :
Be Include '
AR Ynchde < stings hy |
natn > ‘
Scanned with CamScannerChar Sty) } = “sH8ng t Welcome 3
Chay sty at } =
o
“sivfog 2 : Ece-
Srcpy (str, Stra):
PHO Ome outpil %s %o0'| sir i):
& shmepy) + 94-9 used +0 copy frei n Cera
of strito cine shfhga or) sty 9 “to tne SY
Wap for strncpy -
Ht Youlude x Stdfo.b>
HK Yndude A St¥ ng chs”
motne )
3 goth 3 oy §
char. stra.$.J = Sng + wwelome 6
thar trat ) = ece-g% '
SH CEY Cetra, SHr4,"9:
Pant (me eudpal es 7, 0"
, stva"Ds
¥ i
Scanned with CamScanner