0% found this document useful (0 votes)
19 views14 pages

Unit 3 (PSTC)

Uploaded by

konaanandsai2006
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)
19 views14 pages

Unit 3 (PSTC)

Uploaded by

konaanandsai2006
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/ 14

UNTT

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

OAt compile time


orthnos
int aC5)=lo,-, 1, lo,2 fot als1; anbnge
nbe
valus

int aCJ=lo, 1,2,o,-,6,a};v


ht al5=L} eD
int a
(5J=0 ,
int a C5)=A, 23,4S,62eoY dhdr bCio)v.e'ä,i3|
At n time

incude cstdfoh>
2 1

ntmainC

int

int aC53

PrintP C Enter element arY :")


for Ci-o, i5, i+1)

Scanf-c %d", la C])

nd Accessng Arra
Arrmy
mermo
memon epresentation

L nt a C5 = , 1o, o, - 3}:
4x5= 2o t e

B+LIndex
x si2e o int]

tenal wlL ol6


Pointc2000 20o 2001

Base address

a Coj =1 A r s t element Roo0 +D


200
2o0CIu) 2o
a l2]= 1o 2c00t C 2*a 2cof

Roo 34 RoIz

al=3 Rooot C 4 2D14

B+Ddez Siae dintt)


Bief Notes

collection t more than


a
data item ofSar
A l l the data items Are tored in
contiguoU
memoi locations
of data tem array holds ie izo of a

orce Sze has declared, it con't be


churged at
Tun tine ixed bize
ndex stats from 0

kraon as derived data yp


Accessing d ary element is Paster usi
usi
Irdex arra

T t allous t sture dato tn


multidlímenýonal
Por
Inserting &deleta elements rom arta
iS COsty

baund checking9 in

multidimensioral ArYS

datatype arrayrome CrougCcol


3-D

data type arayname Cbloc-),Crous, Ccel

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,

Run- Time nitializatton


int a CR) C], i,

for Ci0 fe2, i++

for Cu=o j 3, j++)

Por Cio i<2; it+)

tor Cizo e3 y

pintl C d alC JJ);

Printtcn")
Roo maJo order

tnt aC4JlJ:

Fomua
ACiJ] B + Cci-Lr) * N Lc

column- rajor order

int aCR) C)

CO.o) Cio) a a) Co)


Formula
ACJL > BA (Ci-+ m -LeD

- I
*-program to print

nchude <stdig h>


itmain C )

nt a l3JC 3J i,
for Ci-o; i<z i 4

for i=o j 3 út)

P C?-=i)
aCIC=o
else i Ci20
a CiG] = -

else

For Cico ies í t )


for ci-oie3ji 4)
fpintf cct. d'" a(iJU): Y pint CK); J}}
*Operations in 1-d
OInsertion
Deletion
GTraverng
earching
sortirg Calo)
OInsertion Oruersi9
Por Ci=o í en; it4)

scant C/d", & ati1);

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

In Bubble valuue tolayt pstin


sortlargest comes

*Operautions d
0 Add'tion
A

nt Cs)ls), Bls)Cs], s[sJ(5J.c, ,.c


printf Ceter ovder o a nmatir:
Scantce1d. 7d, Lr,, ic)
printtc
CGte Orde o b a t i x :"
Scanf C"7d 7.d", .ec,)

pintf Enter d ntegers intv Amatri\n, r.)


for =o ier, i+4
Por Cio; jec ú+4)
scont C . d' ACiJ JD
Pint Fc 6nter . Values ínto matix \n, . cL)

Po Cio ierLi)
Pr Cjoi deC2út)

scan c)d, L eCiJCe3)

Por i=0; ier it)

for o ; jec it+)

SCiJC) =
Ati) i7+ B CiJ
PrintCSter elements ure d , sCi1 ) ;
pint cn)":

BMultiplication)
A

BCrCc)

P CC==r)
Extra loop

tor ci-o; jer iH)

Por Co: iec2 ii+)

sci CUJ-02
for Ce-o; ke^: k )

SC13C-stiJLij+etij Ukj BCJGJ;

3Tronrose Diagora ubstradtion


r d S L3-pimensiora! J

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

Por Ci-o; ie3 i++)

Por c-o; ic3, i4)


Por Cc=o; ke3 KH)

PintCtd"aCi3U C*J)
STRTNG
* triry 1 defined as sequence o characters?
and terminated with ' o - null eharacter

char arvayame C sïze).

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

ut charc) print lwvitc ony one character

*Note r

# include <tdioh enough for all the furitions


Aatchwc
trigs Laets, gethar c utsc
in )
ubed

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

Conuertion om louer toupper case

*noter
we we to conbire ings

ue kaue ome furetians tor s t r i in

Stingh header fAle

streat c)
sr era
sEr empc

trlenc)

strreuc)
strstC)
strlwr c)
strupr)
str chrC)

Some predefined Punetions which 9fues True


or Puse aS r e s l t

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 )

Eaple Reading pinting the sb


Firdingtnythothe stinq
# inelude 2stdio.h>
void main c

char
name Cio)=[ 'a' 'b * d', 'e *1o'
char
clg Clo) "ecUKT"
=

char str l2o3 ch


int,1
printtCEnter the string )
gets Cst);

chqetcharc ):
hite Ch!= * '

strC1eh;

ch-getcharc

3
strcij=*o';
printC 7.s rame)
print c4e', ela)

pirtt S' str) ) putsCst)

ehile CstrciJ !=\o)

Putehar CstrC1J)D
+
strcatE
concateration usig
include estigh
void mainc

char t r 1 [5u, strCR0J

print CEnter stra & strR)

aets cstra)
getscstr2)
strcatCStra, strR)
PrintP c S " stri); () puts Cstri

t i concatenation thout strca

# 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

char strilRo] strR CRo):


printf cEnter stra ");
gets Cstra)
strer CstT2, stra)
strreu Cstr1)

Cstr cmp Ctr1, strR) =


=0)
rintC palind rome"')
else
printP C Not a palindrme :

You might also like