FPL Assignment 3
FPL Assignment 3
How do they
diffet
Jiere Cre severcl form f the ?-else statement
1). T{ tctementI£ epression i9 true. it enecute the
Statement otheruise. jump to ne1t instoucion
-It checks ohecthe given epyession is b0oleon o)
hot
Syrtan
if(enpression)
Stotement 1
Statement 2,
Void mCin
printf (C Eecute me 1 ;
NMIET
Jutput &Eecute me 1.
2 9 else, 9tatementItig used to check an condition
ahd
dependirg on the outcorme of any conditior1 Hhen
NE CCI tollan the qppaopzicte PBh
Gyntuti
if Cenptession)
State.ment 1:
Statement 2;
else
Stateme.nt 3;
State ment 4
Py:-Finclude<Stdio:h
tinclude. <coniço h)
Void mair1O
else
Statement 1i
else i£ (Condition 2)
Statenent 2
else if (condition 3)
Staternent 3;
else i? (corditiorn n)
Statemernt b;
else
default statement;
Ea #include<etdio-t
#itclude <conic-h
Void main
NMIET
it humbet =o;
Clrscr 0
Printf("EnBer the umber");
Scanf ("Id, & number):
Lf (humber = =10)
else
getch():
NMIET
QExplain hat,hat is the purpose Switch sttcrnent 3
&explaih dules associaB cd cotth the use of Switch Stotemerr
Soitch Statement i when there are several octions ard
we have checse only cne optior Trorm the available ornes
coe cah use ScoHch statement:
Syntm
Suitch Cenptession)
Case vCue 1:
staternent 1;
break:
Case Value 2:
Statemeht 2;
break:
Case Value 3:
State ment 3;
break;
default
Statenent;
break;
Rules:
he enpression follooing the keyboand ScoiBch must yeild
ike 1.
integer value Tt must be inteqer constant
The keuLOotds case is tolloced by inteqer r character
COnstant,each constant h each Must be di£fe. rent
4he other.
orm all
the
Airst keyoord
indeger enpre9SI0n tollootng the NMIEd
switch is evcluaBed. The value it gives is seasching
aacirat the constant values thct TolloOS the ase
StcHe.ent:
hen q ncBch
is founid the proatam emecuted the
statemer1t folloing the case Tf Do mHch is found
ioith only Of the case sBatementTollocoing tte default
are eecuted.
Ex &
#include<stdioh)
Void mcin
into:
Printf ("please erter no. betieen 4&5=:
Scanf "% d &a):
Stoitch (a)
COSe 1:
Ptiotf(" Yau cho0se one':
break:
CUse 2:
rintf (" Yoy chO0se. tao;
brecak
CClSe 3:
Print f(" You chocse. three";
break
CUse 4:
Ptintf ( You chocse Four ";
break,
COSe 5: NMIET
Pintf C You choose, Tive");
break;
default:
Printf Ihvalid choose ErBer opo-blw 4&5"):
bredk;
*Output:
Please enter a D0: beteen 1 &53
Youcho0Se. Three.
1While loop i
Syntan
Varigble inidilization
Jnthile (cordition)
statements:
increment o Decternent
int xi * Output
1,2,3, 4,S 6 , 8 9 , 10
otile (n2=10)
ptint£ ("-d");
getch );
Do-ahile locpi
Syntam
Uiable initilization;
do
Statementi
Decrement
Increrne nt (oR
Ex #include..<Stdio h
tinclude <conio-t
Void mgint )
int a,i:
q=5,= 1
do
ohile (i<=S)
geth ()
Dut put S10 1S 20
for (1=1i1210;x+t:)
pintf C"");
getch;
00tputi 1 2 3 4 S 6 8 g 10
b= 20:
int a= 10,
CaQtb
Priotf C: /dc):
ea Gtateent
b;
pint f C"a is qreater than
telse
Print f (" b is greater";
IE -else statement
B');
itf ("a ja qxeater than
itStatement)
NMIET
Give the 5yto for 'for
suitablC cnample stoHernert and cnplain
Syntan: For (initializctlion . cord: incrernerit ||
decrerment
Statements;
eo # include <stdio-hy
int mainc)
:Output
Eoter a nurmber:2
int i=1 ,num
Pritf (" Eoer a humber:"); 4
SCan f d", &num): 6
for Ci= 1, iLEI0 i ) 8
7etun 0;
20
NMIET
y6Conmpase b/w for while' and do cotile' Ooops
Teatue Tor loop wbile oop do while loop
Tnitilization pet formed in done geperatlyIt i9 done before
the jntilization before the loop. the loop separaty
part oE the
loop syrta
2Condition It is checkedTH 0S checked It is checked after
Check before. enking before entering the enecion of locp
Hhe loop body loop body bdy at least once
NMIET
Explain baeak and cordinue th cnrrçk
Cotinue i- T is used to Skíp the urrent itertr
cf arny lcop & bring the cortl to ihe tesrira
of
of iteraticn
fcontinuei
Drtputi
2
10
NMIET
he, most u9ed jurmp statemert
Break:--It j9 one Þf
() nCbredk is uscd to prermuturlly enst
foom a loop o Soitch stutc rnent, before
the block 1s been fully eneauted
i4+)
for Cint i - 1 ; it=to
break
Printf ( /d n'
Setun 0;
3
Cutput: 2
NMIET