C Control Statements
C Control Statements
= 40) Lecmarksea0)) |’ i Pinte Cay") k > ; Scanned with CamScannerf wing (“et”); ‘ vine ee ° . ase marks x) A sts 15 2 cise FF Ccmarks = so e4 C : j , | | Pint (foi |) 3 i mv) y 3 Nested 42 Tn a * Condon FH, cine * alte ed % condAvon -wen we called AS nec ax! 8% Ccond +) ) widur one? grated ustry nested At Toelude ectd?o. hy, mofnc )* a £ fot vor) vor 2 5 Soh 2 \ Prat Center vari ,vare vas) 32.005 * » Scant (%ed %od, dvorl 1 4vara)! 44 (word [evara). wn! Saran): Wag £ Print? vari |= var 2”); ' Scanned with CamScannerVt Cvatt > vara) i Prim! vor & greater”) } elce ‘ Pratt Crore % great en”) 5 Bas e £ PARC von d= var”)! 3 3 Get stetamend: @ WAP wheter a person K&S elffiole to Marry OO nor for male we age >= 25 to many anol fo¥ -Pemole teaqe should be >=Ql to mary. ab Ince £Stdio-h> maine ) 5 ‘ thay ch } int age; . ; Print? Center your gender D5 | | Scank (* 90", gch) 4 Cch ez ‘m) £ Paint? Center your aye")5 Seant Cd", aye), 48 (age >= 25) £ PRC teefbte to marttaye”) 4 Age pire “not eligible tp marrage); Y Scanned with CamScannerS$ Cch= = 4) t eat . 7). Meee paint F (emer your age ); oid : scant Cyd", dage); % Coge >= 21) Print Cet%yfole 40 martage)5 else oe ")r Pint (not etfjfble mariage 7; susith statement = , sutton gace Gade Fe used por mull ple” RerPoe options and we need +0 perform othferent +asle foy | d’Sfereat option. syntats switch Cvaviable » or, expression) CASE Constant { Care break 5 Con case Constant | break 5° default + break 5 Scanned with CamScannerrose a) euerute 4 25) OAS 2 Will, be etecute. Zicr. statement @WA Paludaror programe using’ se =e Include 4 std¥o. h7 matin ¢, ) Oo Aumi , NUM, yesult 5 char Ch 5 he pint Center numd, numa values”); scant 4, ded”, dnumt, numa); print (verter your option c4,—1 #. 1)')S SCPC. Yc, Bth)y cwRith (cr) i hy ? case f+ result =numd numa: pitt #Cvecult ="%d” result) break 3 case ‘_'+ en yesult = numi-~numa; Pitnt# C“vecwt =%d", vesult)s —_— break ; Scanned with CamScannerPO —__ —o“=— Case “x ‘result = numix numa; Prt yecult red “reult); break; casey’ + recwt+ = Num d/ num2 } Printt (“result =%d"), mee: breaks default + Printt O° Rnvalfd key”): break ; 7 y ve Pe Pp to read weak day sumber pint voee day name. ‘hy anit =H Pnclude. caidto. h> moinc ) | : L pany a nt w days ; piint# Center wdays 25 seanf("y%a”, Swaays): _ Cwdays)- Case 4 Prin FC" Mon”), | break; case a: Print! Cues”); break; case 3% print? C“ wean” Scanned with CamScannerbreak 5 case ut print? C° THRIRS") | break: Case 5! ; pitat # CART "D3 preak 5 case 6% : rd paint e C'saT?)s ‘ break} case + 2 . | print? C’gun” 95 S P | break; - | default z my Pint? C'anvatid w days”): : . | } break} vo OWA P +0 PRA vowel cory NOTH UAriy srs. ked Statemeut - At nude 4 Std %>.h> maine > ie id weg § St sire vob ef | chay ch ; ( ynPeat Poe Center any cha'racters”) . q Scant Cel, beh); SwrtCh Ch) i case’o! s case‘a’ + . Printhc" vowel ")3 break;,., , x oa | Scanned with CamScannerCC _—_—_ <= £@& = = ——e Cage \e!+ Case e+ Print+# C vowel”) ; break 3 case ‘f+ Case’: Print? C Vowel”) break 3 Cage ‘y's case’o’: printeCcowel %e break | case ‘y's case‘! + ' Pri? Cvowet”)s break: defautt 4 PHA C Conconant”) ! breaks, @ wH Pe topknr yoo gevler Pin se fnutude 2 Stdio. h > main ) bo ¢ be, char ch $ print (enter your gender ”) 7 seant(% 40", Bch); switch Cch) case \p’* case
y nh
3 bru. 1
Brevarive |_tyoping statement
Bn Looping a pregrem sgram . execittec ~neagequente ot
clatements many type times wut? nine condition Fe Lalee
Joop conc of two Parts, i r
a, Body of me Loop
2> Cont! Statement
Dre contrl statement Fea comnatn Come cond?
Ans that dfrects tre body of te Loop +5 - etenites
wtf) cre, condiion Ye false .
“there, ave two cypes of ops ; ‘
4 pretest cor) emtry tontapled fioen
% posttest cor) exfe contnted Loop
dy pretest ¢ Here she condition Sit reek eter soe
atier %} wit! eater Xnto tre Loop. TP te conolitfon
te ae will enter frto tae oop . ot tee Condon
9s Baler % wi come out of “ne oop
S Posttest Th enor Comtipltect Loop once the Gnd)
OM Got Stakemende uh enenites hen after Aw
Cheek tre condhifon 9 the Condlitfon fs tue
oo
me PUT Ve neaten 8 me roncliton fs -falce the |
Scanned with CamScanner,
( ———S_—S-tll—le_
NE so tue Jpop te exeuited - oY
Bounces ¢ were tne programmer KNOWBS ED e44,
how many mes tne pope Tepes
le fz=to
Heke ame Loop yepeat? 10 oes does 10 rong
Unbourded ¢ siere the pagrernnt fe ik
Known &
how many dimes We Loop Pore
unbounded -
1 46 Fs 20
2 2, ;
Here the Loop Tepeats Infentie mes,
“Wee ancl’ fort are tthe! ipresees ab vahitey
fc a posttest’. > We stph ing 9 r
“There are three types ‘of doopng sBlemed ts,
Ad. wHrlec 9 toop
» for Cy Aoop
'
, “do. uanfiee 5 ‘Loop"” mo
aay id why
a. wWitlec ) Joop
Rea straight trward bop Conefottag oe!
Tia Paadion, condition ot peng “An “aires
dtéfevent nel . j
f a ata ieee:
lPnes:
a }
Whe Cebhatifon) mM
pes yt
* updarng 5
Scanned with CamScannerFlow Chart °
“antisa Irzarhon
Cana ae
OW 6 P 40 pat ~the numbers from \tojo.
=e fnUude 4Stdio. h>
main ¢ )
of
Yt Pets
while Cf 4=10)
priate (alo 795 Pos
Bas
3 t, 9
® war to pwrt woe numbers in weverse order using
Whe. wil. Yn eee
ste Anclude “etal. h>
Mata ¢ )
L
Wy Ink), Pe tos
wantee? >=
" rt ‘
path al’ ds
Per fe 3
Scanned with CamScannera Sng dove o
® wap +o pint Po loving :
RHE Kea LL loom + a
| we Vin
ote Prelude zsidfo. h> yee f
maine )
£ bem
Fat Pots { 4
wihflecf2=t00) | Y
|
printec®. ae ”, : no
Ths “— i
4 A oTWHGA be f=
@ wn ere acter adavle on tom
(4010 uftug while -
Ae Mclude 4ctdfo . h>
moin ¢ )
}
fat Pa1 =
while (Fz = to)
mine Cae as aah Tawi);
2. ° iy ko
tht Dk2 xy Th
J
stor? > Loop #
Snfralfaation , condition and u yin fn a Sage
fine. 99 Yor’ steriement by _sepaittg fbn sem?
colon C3) ¥
“all + Inf:
Dr PS apyerest Soop + P pee?
SyNtat + ¢
for (ntatization ; condérfony updating) ,
b.
Scanned with CamScanner© wap pint [1010 Numbers Uting For ‘boop.
HE include 2 Stdfo - h>
mainc >
£
Sint Ps
ForCisds fas TH+)
patty, ath, 39.9
a
® WAP vo print reverse num bers
HETnclude <64+d7%0.h>
-main Cy
$ i
Gert 85
fm 10-0)
ustng for loop.
1 Movesorig tetas $xeh iy & 7),
wheel fhsdo i pce
PRUE Cd 8s oon ,
Kiang ad :
, 1 / ;
@®D iWin’ pe jto PRat toowm sross. Ulty for oog
i BeTnclude 2 g4dfo.h>
Print? Coed
3
}
Pe
Scanned with CamScannerFe wap wp rhs wrale MEO
Fmm \ t010 ' ae
se fncude <8dPo. h?
matin( )
%
printf Clown datdh» 7, wx?)
3 ; f
3 . a
Ge maitlee tose
do — wWhitec ) Loop é " ,
whic and —do-wifle Lsop ave simflar sexcept while
% a pretest (oop , condivon Will check Firstly -
siren afier Suki ester/“frty doe toop . where
as do—wlfle % the posttest ones the condlition
wen encort Then after Be uSil check, tre condi?
onele condtifor Rs te’ Pr WN epeac tne Beep
conftfon Se false wil ext+ Bom'swe loop.
cahtie the condigon ended: white usenZ colon.
fin do
| syrtat
————
do
,
i white (cond $4400,
Scanned with CamScanner~ Flow Chart 2
do—wlhe
do volte
too:
A
O WAP Yo Pant tow usmy do-while-
AEPnclude LStdid hr
matin C )
{
Yat feds
do? .
L ‘
Printt Cydin”, 9)
Pat 5
Jwlte Ch=10)5
2
® wap to pit staple 4mm el to 100 numbers «
Ht fautude »AStdTo. >
Mafne )
£
fot F218
do
ia
i OF. 3==0)
Print? Ny Wen,
; qa hd) V5
Scanned with CamScanner3 wwhtie ers =100)5 |
3
@ war voprat wrare mite foltowing Lang|
using do-tolifle . |
HE clude 4 Sto. h>
Mohn )
{ |
Tot P= 3
do
PPLE Coxthd © hdin’, f, tomt)S
We
} vokfie Cfe=to);
$ ’
D WAP — snane combinarfon of cuftch ©) and dort
# Tnelude ectdio.h> |
main ) bo bd |
3 ae
fat opifon 5
char ch 3
do
‘prinig(%4 Hel, 2, welcome ,| a Buea ")s
LANE *+1.4", Boplonys
E atten Coptfon)
£
case 4 6
phate Cueto”), ba
break +
Scanned with CamScanner4
Case at
Pint C welcome’) 5
break 5
cose 3
'
pial? (Saye) 5
rear 5
default +
Prt C Savalfd key”) 5
break
3
prin CS yaomt $0 gontfnue yl”);
seantic® 9.0", bd:
Joule cow 2 = yt
}
Nested Loop #
Dn a op Pe there Fo mother Loo}
Nettedl Loop
pie: are Biypes of Nested tooP
“atte ¢) Loop
2% for ¢ ) Loop
% do-whilec) top
p thy, We called as
Nested wWhilet )Loop #
Gn a wlte oop 2F nerve H anodner woutle toop
sen we Called ac Nected whfle Loop.
Syntat!
wile ccond 9)
condy © Sratemend >
white Ccond 2)
i
ca 2 Slalemed +
Scanned with CamScanner~O wap. +o pit fntwe folloutng —formert
Se fnunde 2 Stdfo. hy
maine 9 ! :
L
tnt Pa os
Witte’ cee bey
i
Sais)
wusle Cj2=%)
printhead", $y,
Sot;
nol bing G ns
Pes
3
| 4
nested forextoop &
In a for loop % tneve Fs another Py Loop tren
we Called as vested for loop.
bn
Scanned with CamScannera Way
ee
orc cond 1)
i
condd Stal Omen
“fore cond)
i
Sat 2
5
3
Flow Chart 2
Pow Sang
° ° j ested, 5 '
OnNAP @ PIE uaPag dor Loop ~0 pant th tne follo
Rag format * *
wR
ae Pnctu de z std?o.h > me
2 Je ee
maiinc )
4
Wnt 4, 5
Matern: ‘ j
SWHey
PHnte In”)
b>? mec 05
Scanned with CamScannerie WA mudfiptrtatton fable. tufug MUNN” for fog, ©
( 2 Rug
AeTUude 464470 sh? 2 4 6 Big
mane ) SZ 6 4 12 te
48 12 lear
3 Cy lO 1€ 20 as
nt Pfs
NS
fore Feats T2253 f+)
£
fos Chats fa=55 fae)
i '
PAO cng aa, fx3);
. fe
> |
PREC (NDS | x
yes oS \
J nl oe |
3 l= (e
Nested do-whfle-e 1 Leop &
Th a do—whtte Loop PP. dmere Go tothe do -WhPle
| Loop then we called as" Wetted do-whifle’ +7 er i
Syntans 1
do r wae
| i
do
£
3 wile ccond 9) +
J white Ccondn); 4
4 WA P 1 PRR Fy the Pollowseg
Uing nested do -while Loop,"
0000 =
2
o
7
wpe sere
Scanned with CamScannerGncluce £4 dip-h>
main )
i
Tor hoofs
do
i
tae Jol
do
Bboy
PHO Cd techy 7,595
Sat 5
3 wwe fa=u) 5
pS On"
tts \
pwrectn2)5 ‘
iis 1 kK
uncondiivonal statentenice- aid
swerve are ‘3 typeS of unconclitonal —statemenss
in see. Ava
4d. ‘Breaks
2. continue 3°
3 goto, : psa, (0
4. break 2 Fr Ge used to 4ermBnet -the Execeut%on of
Joop eincondiWonattly udkrg break, Cratement . %
uced as Exlt from ste Loop -
break can be used % while, do-iwhfie and Ay
oop s
* “eevee
Incase of faner Lvop ey byeak Pp -ferminefs the
wop of Srey ony .
‘ |
Scanned with CamScannerOwnwnp Luhy beak have mtu
ae Anuude 4 stdfo-h 7
main ( >
Fort Fs
for Ci festo5 M4)
L 7
PRA CY, NTIS
#209 = =|9)
break :
3
y :
Continue £ Se% used 10 skp Ae Slavemencts and
Conte wine neve -PHeration . contfrue % also Wed
an wikie, Poy ad do-whidle Joop
DO wap to peat sum of ne number, udig cone
fe
statement.
“3b %clude 2Stdfo.h>
maine > sum = Sum4nur
4 4).8um)=0#to slo
Tea T, nue , sum=o%, 9, Sum = loH20 = 20
for (fel, Mees; tHe) 8,.8Um a04gb £60
4s Sums Gost = (00
PRO Center any number’);| © SUM = foots =
scant (+3 ") gnum);
¥P chum 207 i
fh ”
PREC negatwey:
conifnue ;
Sum = Um+ num 3
3 ;
Prt eC su 3”, sum);
Scanned with CamScanner, ees #
goto Statement Ye Used to Jump From one. ped fhe
ro the tmetney line Yn a prgTAM. .
VEY 040 HalemeutS musl avd should have lable.
“we label name ghoutd be ended wita semécolon,
forward :
oe
goto habel, back ward
1. ae =——_
~ . Se dabel 5
\; -~ oy
van got tabel ;
© w AP uctyg yoro Statement -
ae Include a Sto .h>
mofnc )
£
Prt num= 3
Yepeat !
print C% din” num):
mUM+4 5
PP Cnum c= 10)
qoro ae
5
wale 40 phuct Pn “tue fottorchog donuat wy
fretude