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

C Notes Unit 2

The document discusses decision-making statements in programming, including if statements, switch statements, and looping constructs. It explains how these statements control the flow of program execution based on conditions and includes examples in C language. Additionally, it covers nested statements and the importance of loops in simplifying repetitive tasks.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
2 views19 pages

C Notes Unit 2

The document discusses decision-making statements in programming, including if statements, switch statements, and looping constructs. It explains how these statements control the flow of program execution based on conditions and includes examples in C language. Additionally, it covers nested statements and the importance of loops in simplifying repetitive tasks.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
— Go wnt IL ee Candienal, Statements 3 are used tehuve we ated to make me =) » dedsfons and based on these decisions Wwe voll exccube she nett ~ Bloc of cock These statements ull dicide ‘he disection of the How cs) al the program execalion. 2p, thace are ahi call os decision 9 making statements Sos gp Ab’s we whl dake one condition Hf Fhat 3s hae # will * « = execute block ah codenite not & ustll erecale anothers block of Sy corde: SF Wey oe distdid floors way selection Slolements, ( ~ too way selection dalements , mult Loony gelockion Stadements Ss S 0 way selec selockion Stalements 3 5 eee 5S 2 > at Stelemend 5 : 5 she H stokement tells us that a condition fe toue tt > alll execate dre set ol slademends fnsidhe the i”gpobemen}- dnd tt any Stoleneanis ore there oubside those oil be. eatecuded aw ™ Syntax 5 a Ceonditfon) L Stokements 5 a + Flowchart oVerVUVOUOVDYOIUVIVUVDBDYE Gramps Ht include fmt main C) 2 Int a=65 4h Carts) print Cte!) 5 a paint Tran ypu"): ‘ oedpuls Tank ypu: => Tea_toay selection slakments 3 > i-ele Stalement ¢ 4 he Uo stalement ells Us that % a condétfon fs true 7 will exeate @ block of statements Inside the tk condition, &! condition goes fole ran fF ustll execule the ele block stabementé ynkox e §t Ceondition) g Skabement sag & che 5 Stodementy ay stobemews5 ~ Eero choal s Slalement Stadement & =Finclude Exomples i Ab findlude Fok main C5 q nt ayo C5 Pott Center arose valuts "3 Scant C+ 4d nd hd") Sa, 9b /3693 i Carlo 6§ aed § prio largest no ts ved in" ay; ( g else 1 Cora £& ore) § print C largest 90 {8 “ed 49", bY; t ase 4 ° punk C largest ne *s Fo" OF 4 ham 05 ovtpul § Enter aibic Laburs 5 1o 15 E : largest 90 isos $b as defined as th block inside another tf block tS Known as etadement- af the vst &f condition fs aut then FE will = nested Hl clolement : rested tt oe Hack ® condition ond shen 41 wotll check the Insicle th conciftfon Tf Ahok condition % Agus akan H cotll exxecabe the 8 plock »t Ahab conthi#ion 8 false Ab sll execute elte block. y ee st Condition 9) it Cconaitton 2) sstodement 15 a ue Statement 25 x x ebe Statement 35 3 ae woxoe eye BY —> Ecarple $ Ab nclude int mein) § int as proto? Ceniey a valet 5 sant CO xd", £095 fl Caxag-=o) £ i Lawlor =0) & e "Ye pring Cra is divistbla by “72 * che % “ prinif Ga ts not diuisthl by 45 x iz elie print? Ca ts odd numbes ” 2% = velunn 05 + gepde Enter a Uoluat 16 © fs dluftsible by a. => Suitch Stalemenk $ CR The -suotich lalement ts allows us to execute one coda £ Stasement 35 block among many alternalives - suiitch Cexpresston) E L e- Case expresston 12 e z | Statement 15 c break 5 ¢ x c Cove expression A% <¢ L « Stosement 85 Cc bveak 5 € x € default ¢ € « « 4 q « c Flow chant hs irs | SUNDUSEd TT dd oud wu ') rs MOU U UU yy — Example! Reeves HE fnclucke ¢ S80 fat maine) a Fok NuMbeT 5 print Center numbes")$ scarf t'%d" » § NUMbeWs Svotich Cnumber? é case 13 prinig Coumbes fs equal 4 9 a: breaks 3 1 case aS point Crumber 8s equal © 8°95 Yoveaks fe case 3% printf Cinumbes 4s equa) © 3 05 breaks 8 deloult ¢ prints Ce rumbes Ss absent"); ae weturn 05 x Enley number Q fumber fs equal © 8. => kooping or Mevation: Tre Looping can be defined as depeafing he same ael o frsiauctfons os prowss Multiple Himes untill a spedfic, condition satisties Ik fe also Known as Herasion . S&S Athy looping ¢ ee = Te Looping Simplifies Xhe Complex paoblams fnto the eaay ones. | St enables to conteol the fhe flow of the program so thet Instead of waving the Same code again and egain 5 oe can execute the game codt fox a Fintle numbes of dimes tor excample Ff we neecl to prot “Kal~nada! 10 -times then, Snsteadd of using the patntf -Stofement to mes , we can else print ona Anside a loop which SUNS Lipto to Heragions. ae ose: > & provides eads seusabillly . > being wops, we do not neech to xecovite the same code again ond again: oe ea > For lop : > bile bop = do whi Loojo 5 nested = : =¥ tos loop ¢ inne | for Woop fs a loop 3 a bop Statement which enill excel Yhe statements untill the gfuen condition gees false « — Sylow ¢ Jos C Snt¥alitalion 3 conetition 3 Sncrement [decrement ) g IPDIIIGIESS Stakemends 5 . Flowchart! aN ) Snitaliation TMS Yee aaaddddd Anevemend / Decrement Ki > Example $ ap include 81 i0-h> int main O) x in Ge for i204 fe25 3 TH+) paint C ZAd Ww" 9 D5 ® relarn 05 ¥ gee ° ’ Dy 3 u 5 2) while loop 3 St will execatte Ahe block of code sepeatectiy cintil the gfuen condition aoes false, but Lhe main diflesente betweee for and tolile ts syntax. —> Syvdas 5 8 Anikalitation; = dle Cconditon) . state mands § Snevemas/ deevemend 5 > Pewecharl : eS Get) inikalitation Exampbsé fncluds fink main’) Ink EDS wWls Cie=5) print C 4d "7" 1); tes; . vettrn 05 eee > ALU p= > an do while; 4 wl) execute the do block fist and then 9} W\ check Ye conditfon. 4k Ahe Condition Is Yue Ch will voll execute te do block eke TH wilh stop execution. > Sqdax § Ses Habitakion 5 do = Stasements 5 Ancvemund | decrement ; Feabite Condition) 3 > Fovchorl 3 Rnside do 5 Example fs ab fnnetude Int maine) do print Ce) 5 Akay Zoohile Cfead y Yekun OF a oeipahs, Ww at Wi £8) ruested Leeps gt ts nothing d boop. of the Kyst loop inside loop and 8 insich loop toda Unde PIWAGDA sy dg GIIIIIIIIT IDE SG but lop ansidle anothes loop fs known as reste Condition ts hue then a will enter into ee alco (tue EN 4 ewill execute the condition fhe condition gees false . > sy ublare ¢ doy Cin abitadion 5 Condition 5 Incremen! (Decrement) § vvwevvvvwvvwwwvwvugs fos CidRalization; condition; Incvement | Decrement) Stademunds 3 y Feary aAincluc ZStdio- hy int ‘mainl) t tnt f, 4, ws paint? Center not vows? 5 scant C%d", $095 doy Cielg feexgaaiy fox Bats tect 3 ht45) q print Cede" 5 45 x print ww')s 4 veturn os 4 Sudpub 2 entes no ol great € 1 bao Lis 3) 123 4 123 us t2auceG. “N > loop Consol Statements: tA RR Thase tye the Slademente edich will contvol the bole toop execulon + 7 They ave, beak continue r to. — break 3 NT Se votlt ewecede the block of the coda until the break Condition orvives, On@ Tncak votll encountes the execadton veil be stoped wrave - SINE fos ( sudalitalion 5 Condition 5 Snesement [Decsemand’) Stodemands 5 break; 7 oe enelude < Sichior hy oubpul's Gi im main ©) , welurn 0% y . -sleaes — Continues oe cia the “tts wil lurthuy Contious the excculfon of Iolock af todo => Sudan: dow Cinivallralion 3 conditions Sncvemunt (Decrement) & Stalemawhs 5 Conkinus 5 i) ce include zstdtosh> Amt main © ) 4 Ant &5 fos Ue05 135 t449 2 paint © Hello” ys eontinus 5 3 sekuin 03 s geen Yello Hello aello ‘ » = ou. oS > goto stademend iso unconditional Sump Loom the qt ss) & to. labeled ataiermend in the Code « s S Syphass = oto label4 5 » f. : Navel 4 + ; 5 9 Statemends 3 ° a. & : > Kecompl Ainclude £sidiosh> Prt main Od Lan ar05 fox Cint #03 (42103 fer) sasasts a Che =5) qolate addition; Y¥AIFYUWWWUVVHWUeE YH \ 5 t » add tion : : a : pein © 28", 0); 7 i ? & aelusn 05 2 Batpal’ Sy. >

You might also like