Unit 3 (PSTC)
Unit 3 (PSTC)
o
XA of elements /collection Hormes
datboreD
aHS Lit
Snta ite
name [izel;
t a type array
int a CiOJ
chor bC 3
floate Ct
double d C5];
Rules
We can store data items
many
All the data items must ba
ame type
ELint a'l -3, d
Ploat bl 4] 2-2, o-6, 3., 4-7
char c (3) a, b, c
t aC 13, t C Xu
we must
speck the
sze
nta C Jx inta C3x2)
inta C-5:X a h b a Cu/2)
nta CRA]: int bi intralb="RLV
Inítialization
sh
o b qo1
0At Conpile6tme
At Run time r
incude cstdfoh>
2 1
ntmainC
int
int aC53
nd Accessng Arra
Arrmy
mermo
memon epresentation
L nt a C5 = , 1o, o, - 3}:
4x5= 2o t e
B+LIndex
x si2e o int]
Base address
Roo 34 RoIz
baund checking9 in
multidimensioral ArYS
Enample s
i n t aC2,C&3
*-D Avays
Hnta datrtype arayname Lrus] kol )
Cxinta C) C3;
poitialí2ation
pirectr
int aCRC 0={ 1o, a0, 30, 40, v o
at 3C33-i t1o, a, 3u, 4o,50,us
int aCJCJ=£f 0, 20, sojoh, t so, 6o, io} so,90. 1o0}}
2
Indiuidual
naCa]C3]
Jcation value
a CoJl2) = 34j
Io 2634
a CoJt 0 =lo 40
alojC1) =16
aC1JCR) = <0,
tor Cizo e3 y
Printtcn")
Roo maJo order
tnt aC4JlJ:
Fomua
ACiJ] B + Cci-Lr) * N Lc
int aCR) C)
- I
*-program to print
nt a l3JC 3J i,
for Ci-o; i<z i 4
P C?-=i)
aCIC=o
else i Ci20
a CiG] = -
else
Deletion
int pos
scanf c /d', l pos)
for Ci =pos ien it+)
aCi=ali+J
searching
near searchb
int lag =0
or Ci=oi ien, )
i Clog = iCleey=raCi)
rot ound
Plag
printPcelement)
breal
else
Pint CelemenE faurd):
nay search
must be in order.
Rule A the elementsb
ortirg selestion sort
Bucket Sort ek
shorb,
Pes Bubble
Sele ction sor Cizo ien, it+).
CaCiJ> atiJ)
3| itemp eali)
aCiJ aCiJ:
a CJ temp
Bubble sort
1o
to
*Operautions d
0 Add'tion
A
Po Cio ierLi)
Pr Cjoi deC2út)
SCiJC) =
Ati) i7+ B CiJ
PrintCSter elements ure d , sCi1 ) ;
pint cn)":
BMultiplication)
A
BCrCc)
P CC==r)
Extra loop
sci CUJ-02
for Ce-o; ke^: k )
tzkock
Initializ0tion
Opirect
int aC3C31 C3] =l2,3}, t«5.63.{z,t,13}
2to,, 1a3. L, 2,33 4,s6
7 . 3 . s.6, ,333.
eun time
int aCajC3(3J:
fo Cio; ie3: ir+)
for ci=o; ies, it+)
or Ck=0; ke3, H)
scantc zd Lat:ICiIC=3
PintCtd"aCi3U C*J)
STRTNG
* triry 1 defined as sequence o characters?
and terminated with ' o - null eharacter
Ttialiízation
pirectr
E char name Cio]-{'b, * d . e 1
Null
char
ela t J="RGUET"
NO need of \o
char
aCto ="welcone""-
char bC J=t'a, 'b,'C, a,e, °s
Run tme
To Read/input characters at Rntime tree
ways e possible
Oscanf C' e , 15
ets e Line of- characters
e t charc bny one character a t a ttme.
For outputlwite
O print Pc
putsc line wite
*Note r
Pstings
initialized
are Constarts, hle can't
od once
Operations
stinq concateration.
Rirding eny
s t r i a replace
s t i n g ird
dewsa C lower case)
cunuertion Pon u p to
*noter
we we to conbire ings
streat c)
sr era
sEr empc
trlenc)
strreuc)
strstC)
strlwr c)
strupr)
str chrC)
Talpha
sdigit c
i s alrumc
isspacec )
1 lwr C )
to louverC )
tupperC )
For conuersions we ne.ed tv use stdlib:h
header file
al23
atu i )
ato C
ato-p c )
char
name Cio)=[ 'a' 'b * d', 'e *1o'
char
clg Clo) "ecUKT"
=
chqetcharc ):
hite Ch!= * '
strC1eh;
ch-getcharc
3
strcij=*o';
printC 7.s rame)
print c4e', ela)
Putehar CstrC1J)D
+
strcatE
concateration usig
include estigh
void mainc
aets cstra)
getscstr2)
strcatCStra, strR)
PrintP c S " stri); () puts Cstri
# inchude cstdio.h
vord main C )
intico; J=0;
1
getsCstri)
eSCstr2
while CstJJ!=io)
whle CstreCJJ!=0
stra Cij=str2Ci]:
i++
2, t t
str2CiJ=°\o
Ce
puts Cstr2)
Polindrome usig s i i hardlir functions
inelude cstdio:h>
inelude cstrg'h
oid moínc