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

Unit 3 Pps

The document discusses various programming concepts, particularly focusing on loops, arrays, and sorting algorithms. It includes syntax examples for while loops, array declarations, and bubble sort, along with code snippets for practical applications. Additionally, it covers topics like initialization, memory management, and finding elements within arrays.

Uploaded by

ronakyadav2004
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)
10 views19 pages

Unit 3 Pps

The document discusses various programming concepts, particularly focusing on loops, arrays, and sorting algorithms. It includes syntax examples for while loops, array declarations, and bubble sort, along with code snippets for practical applications. Additionally, it covers topics like initialization, memory management, and finding elements within arrays.

Uploaded by

ronakyadav2004
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

(e)

and A
condition is
whileL0op Ceondition)
contoo)statementthe 9fContoo
statementt tatementr aseehat pasts Looping
Synta bodaythe af
be<oe
contol
enty othes ÀSleep in
statenentr
epeative
iii) it)
)_Snilization
condition
Lihile ) ox statement
[UNIT-3J
Temination
condition. Step gepeatsdy
executedwat
SatiHed
taBement stateneats
y Modification
i updatiam. afex knoun
koown
the
proqam
the Can

bady
eigbder
planed be Locpiag
statement Consicttwo. of
Contaolleep
then bodyaf
plbefacedoye of
ii
the teative alo Pg Dt

Lesp khewncexteun a
B+

Sal

pintWA
to
# #
<ste'oh2
ladud
include
printf l<10)
(while (
2
conio
Statement
block
h uptateT Conditior
Statement y
updatim
’nzatien
timesten

ulwhiinlolgope
Pg D

B+
Sell

#incude
maun
int )
#include
steliah) < hAP
inclde t
AP
numbeRJ ?
}ntf while cScant
i<=n) %d,
tn) prinf
ety
include
to
to
Cconió h <onioh7
<stdioh
Entex
%d
a Z
sum
umbes"
)
imbey

Pg
Datua whiwingle D

B+

muhtint 1<=5
twAP to
whileCis1o) pintf inchude
tastett An
(
Eatex
G=] paint
<steia

a nn h
table Sum&2=5
bumbe" |t2
=
table
o =3
L
a 6

qlven
3436Sun =
i:4
table)
ni Pg. D
nwnbet

B+
Sy
WAP
manfnt ) minl)int tt
include
whilecis
num)
to
i*fact
fact = <stio
end
h2
factenl

of
numbi
qiven
digitss
a
qiven
Pg. Dt

unbes
CB+

WAP

(nzowhile
Cont =
find to

count
t)
Yeee

acaunt
digits ot

a
qiven
Pg. Dt

mbey
7
B+
Qu5To Qy
it a
e7 4

WAP toWAP
To chck Tó
To
dn Scanf numbe
printfntyne
tn0
white ( BinauyDecimal
t
check pint. check
to to

|i on bihaky tocalculate
given Seecalculate x fieonpalindzome
givenumbe
convegAOn
Decimal
gren
calculate
aci
gianmta.
humbe
ve)nCon (hCp)
HcF. teies See
withautfactoial 7

i
peefect
using
of digit
Sum ?
0r qiven not0r? Dt
pouer Pg.
net
tnchan nunbe

2 B+

Sol

ìnt
while za pinti onan
veid

to t
Endey

thy
numberJi

Dt
Pg.

B+
Ct<=y)
while int etse
(d)i
getchJ; porint# t 1Pmnt£{nt
pandme
fintfpaliadami"
YE1, ,

þ=|

Pa

B+

Sol

(i<n
while pint+ vefd

hi(a
le naun
snput
l
)
he
numbet")

Pg. Dt

B+
pnntf
()3maun
Veld

Entey

a
decimal

Nåmbey";

Pg. D

B+

Syntax

StatemetyfoxfaitisatieA
Statenert
btoctj
Statemant contnl
Entayoop
atmeny block
LenditionSnitaizatign Statement
updatin

;
condihon,

Pg Dt

updaci
mn)
WAP
and
int Void
to
tiinitt) for to
c
) (d",i
9etch
C); pantt psintf
n,
find piakto n
e-,o- humbesd
SWm

betoeen
sun
wing
odd
n.
to1
Pg. D

unbey

B+

fibonacu
SesieA

Scantpint
(d
ele
6|2ib(nl

Endex
no
n
temy 3

")

Dt.
Pg.

B+
)

b2
t

elye

pnntf("%d",cCab i<n-2)
while
setun ab

363

Pa D

B+

p Boeak
brek tatements
Jumpinq t statemert
9nee I Syntax -
utr block
statement

(izza)
if contnue

lortine;

Po Dt

B+
Array)
collection of simiios 4ype of data stoe
Locaion data
Ln
consecutve memo"y
stoucture that used to store multiple elements
of Same type
of assay and
) Declaration of Ayy ’ 9+ defines si ze
ty pe of a a y elenntr.
Syntax :
data typt - asay-name Lsize;
eg’ int maks Cso] ,
int a C5 0J;
Memongentati on
Repre, 53sto 45
a[49).
J.
Base
addye
Jnitiaiz ation
) At comp)le time ’
i a (5) 1,2, 3
a(o] a) al:) ) a(+)
unt als) U,2,1,t,$,6,7o shaws esuer
) Runti me '
unt a(so], n;
ointf ( Endes numbes of element);
Sent ( d,n)
for (i:o; i<n; i++)
Chaacteistics of wAP to eadn element ¢ find osget and
condtant value.
A ay size muw be Smalleyt element f that assy
continuow Cadjqcent) memoy location.
Ary elernent stere at +inducle <steioh)
nd higher add yes # jncdude <coioh
coTYS pondu to nt main ( )
statte data s tructe.
Array is and cannot be
aloc ated dusing compile time
Memoy isdaying int a[soJ , n,,max , mn j
runtime.
changed Phnt+ Entex numbes of element
Pointing asay element ’ Scanf (t %d", 4 n);
for(i =0, i<n i i++) fox(i=or, ien; itt)
)
poinf (" a", aLiJ)?
Scant (" ya", aCJ);
gey Nit a proqramn te read n emen and disploy mgx = aCo;
them using 1-D aay?
for(i =1; i<n,it+)
#incude cstd'oh>
# inlude <conioh> if(max < aiJ)
int maun ()
max = ali];
unt a(soJ, i, n ;
mun = alo)}
printf( Entex numb ay o elements):
fo (iz o; i<n; it+) if ( min> aCiJ)
printf ( Entey an clement))
fint f ("yd 1t, acJ) ; pinttMinimun lement- /d, min)
pialf( Maximun element - d" ax );
/
Cund
elementr and find Laugest WAP to yeao mumbesy.
of that asoay? Find the osLart and oecend Jay ut element ay
Second Jauyest lement and second Roy es+ element
Swao the pasitHon of Lasgest
<stdioh>
t mo #incude then prnt he ne aosuy.
4 incude <co h
So)y +#incde <std'osh
int maun()
seclayej wnt manc)
nt a Cso),i,n, max, Pas , pos;
pintf (" Chtey numbe elements ; unt a[so], i, n, max, Seclasye
int temp
Pintt ("&nteY nund t elementr "):
fay ( i= 0; icn i++)
);
scanf ( y.d", e a li)))
3
foy (i :1}; en ; i++)
if (mqx < aci)
mgx =a li];
sec lasye = alo;
tor (i: l. i<n;itt)
if (Seclaye < aciJ 44 aci)!= max )
Seclage = aloJ;
foy(i ); ien, i++)
1
printt ("setand lageyt > %d, seclasge ) secluye
pos a 3,
pintf (" Second layest d", seclar>; for (i z0, icn,(a+)
temp oa (pas 1]; 1 pntt (" a", a Ci));
a[pas13 : a[pos2J}
a[pos2]- temp
printt ("New aay"): retun 0j
frl izo; <n ; ++)
and delee an alemen
1printt ("%d, aliJ)} input fo an
NAp to take pnnt the meu aray?
asay ond hset foom specjtied pasiH on. nd
WAP o tate input S
element at given þaition. unt main ()
#)nclde <stdi'oh
Sel int aC50], i, n, pos s
Int man(){ demnts);
pintt ( Entey wmben
ntaCsoJ,i,n,vady pos ;
printf ("ntey umben of elements )i
Pnh+(" Entey Puiion for deleion a elenent
scant ( y.a", 4n)
for lio; ien,i++) Scant (" %d, 4 pos) ;
1 fox (i= o, lan;itt)
printf(Enter a C%4]= , ; pontf(" Ender a [%a] = ,);
22
Scan f("a, tali]): Scanf ( %a, ali])i
pintf ( Entey element and pos)hin j
foy ( i pos ; ini i++)
foy(i=n-l, i pos;i--) aci): ali+)];
3 Pintf ( New tray):
a [pos] vali foy (izo -n; itt)
n nt
pintf ("% a", alio),
printt (´new arry ;
find the ay
4 WAP to input two aays and aays and
ponding elements 7of these Sorting 4 Seting is a pnces aoan in9 aay
then print the mew assy elements in pasticuay ooder t can be eighey
So]’ tindude Cstelio h as cending crdey dercending order.
int man() ) Bubble sbrt simple se vting algoithm
(so), , n} Soyt
int also], b(50), sun which used to a 9)ven
lements pjded in the fom of an assy
printt ( Ender the nuumbei lement) eements cne by one
Bubble sort compases all the
and sort them boyed Dn theiy values
with
fox (i-0, icn, it*) steps fist element, compasu i
with
the next element ot the assay element
1 printt(" enter aliJ = i);
94 the greater than nex+
usent element is
Scanf ("%" e ali); of asay then swap them
hn next Wement
94 cusent denent w le
the
then move to the next elemen+ nd epeat stp 1
fos (iz o,icn,i++)
No of elements = n
alo) ai) a(2) a4)
134 4 Numbe of poes n
Scan f ("%a" 4 bCi):
|2
for (i=o, ien, (t+) 12 (2
4
Sum CiJ - aciJ+ blI) 13
4
pinÉf" tttil);, 4
4 4
|(3
NO
13
4 14
|4)
2) 2nd pey
5 No
4
2 |2
|2 NO
4
13
13
4 4
J4
4 4 temp ali]; Time competiy
alj) : alj+i? ;
12 2 a[jt] - tempi ovder
|4
4
printt ("Stel Ary :
foy (iz0; i<n; itt)
|2 Suep
12 pintt ("% a\t"
|I3
|14
code for bubble Sott
unt aCsoJ, M, i, J tempP; Seavching Seauching Procey o findin
within ist eement stoY
prntt| Ente no ot elements)) element a
ny ovder
Scant ( a', tn);
Lineas Seach :
fx (i:o, ienj itt)
prntt ( entey ): code nt man ()3
unt a [so), , n, val, o c - ;
Pointf ( Egtey ns. element:
fo (i=y ; ien itt) nd enty element to be
Seahe.
itCa(i3 >aljtiJ ) foy (i=o, i<n,it)
L panf (" Entey aC%.a) = );
Binasy seaach is ppliiable, ony n sote
Scan t"%A", 4 aci));
(Tinecompley asay efficient Hhan ineas seach ifthe
o(n)
size of the asoay is Lasge.
to sox
for (izo; i<n ;i+ +) To pefom bìnasuy seasych we hawe ay
(açi = valu)
elanents and then peyfom the fo||0 uing steps-’
O’ Fixst ind out the the asoay
middle elemen+ of
Pnnt" d element is peent at d posiion) Compasue the mid - edement witth seassching element -
val, doc )) asu thee coyes
e These
brest; i) 94 middle element seanching element then
Seasch s Syceeyful.
") 94 mddde element is qreatey thon seastchng element
then seach in fist half < the a y and change
he endiny
{ pint f aCmidJ > value
("yd element not prynt
Seych s nsueeeutul"); end = mìd -
o) 9¢ middle elemen+ ley than the Seacrcng
element then seach in the second hat the asy
and change beginning the y
oppl'ed fo both ay
LineaY Seasch can be aCmia] value
wnsorted Sn this we acc ey
sorted beginning = mìd+|
each eleent by
Sequencey and dheck
whethe it is secanching element oy t? (nt maun C)
element found the asay then
4 is succesfl seanch otherwite Seasoh ùnt aCso J, , n, end, beg, mid, found =0)
called
Called prinf ( enty
Disad vantage: . 9+ is time conswmuny
hove eaye any.
pnntf ( e e aL/
,i);
scant (o %d,4 a CuJ);
Pntf( Enter elemnt to be
Sech &- pimension ad Hrruy.
Scanl(%d, vy;
Decleahon !
bey o Tme comfleaij >yntax !- data- type asay-name Low sieJlolumn
size
end (n-1);
int a C2J(3);
while ( bey= ond) Compile time 9niizatoy
Memoy Repreyentoton
1 mid (bey tend))a; i) ¬lenet by Element ’
a CoJco)
i+oCmia ) =: vay 2 3 4
aloJ Co) 2
4
aciJCoJ aCJO aCiJ[27 a[i)a 6
dex value.
’Runtme initization
bresk i) collecti vely :
unt alioJC1o), Y,c;
eye if ( a[mial ved) pintf " nte no o os and calus; int alJc3): ,,3, 4,5,<};
Scanf ("%d %d", ,4c);
end md)
elye
for (jo; j<c; jtt)
bes = mmdtl
pintf (* Entey a[Xa]CJ j):
Scant ("%a, a[iJG3):
if (bey> end tt foun = o)
Ytun o
}
retun D
and pint hat
WAP to input 2-D
CWAP Paint Sum of al dagona! element
sy ? matix ?
# include <steieh
So ’
0nt man()
int al)[io) ,,j!
pMntf("Enter nt muinl)
Stan+ ("%d %d", fy, tc) Sum = 0
int aCro] (1o], n, i, j
for (i*; iev; it+) pnntt (" Eney rdey matnx )
for (j=o; i<c ; j++) Scun f("%",n)!
fy ( iz o; teY; C++)
scaat
Scanf ("%" t aCJG));
foy (i:o; ier; L++)
2
pnintt (" %dt, a Ci)j ); ue WAP Gnd tonspve matnx?
to addti m d tusnatix ?
mulh plicaton tuo matx ?
Print ("\ ")) wAP to find
Yetun O;
tinluofe cstd h 0nt maunl)
o
¿nt LC,,
a [ioJ[lo, b(1o] CloJ, cCe)Ci, c:
1 int aLolt, s,
c,,)i Ftmyh),
printfCntr yovs ant co}wmn
Scanf ("d d , 4 ),4 i);
Scanf (d %d, e , t):
column Seend mmmir);
p i n t t t yows
fo (i:o; i<;itt)
fox (j=o; jec)j+)
pintf ( Enter a C%4]C%a) ,j))
foy (jio; j<e, ) j++)
sconf("
Scanf("%". 4 a[iJSJ);
fo (io; / c ; t t)
for (y':; j j )
a CwJ[i
pntt ( Enks b[4J[%] , ) ;
pessjble) Mtiplicchm
hot it l"pnat

retn
0;

fist colurgs
d and Ytw
3 );mix
pnntf(at alre[), nt
e(1J6));
?C)man ut
j++)
ij4i o(j foy

22* |+

cciJJ)? .d, fmn!("sum


j<4,,j**) for(j-
o;
it+) (eY,; (izo, for

You might also like