0% found this document useful (0 votes)
22 views

Chapter 4, C++

Uploaded by

jangrasahab4556
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
22 views

Chapter 4, C++

Uploaded by

jangrasahab4556
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 25
4.1 Introduction ‘na poram mase up o cat single salemets the paver ana asset tert he fw of ‘Storaton lz called tne eon fw eset Sumi! ne he ciel ow is save re spe the preyam as show niga Pegancvasodnuce ied te tow leas! “Ther are Wee Npee of cite! ences. (AiConctions! Control Tranter or Decision conutatarigeenecnstoraseeee ena (0) 8 ie sataent 109 sac store © putcretua ss ane Seeas aanseeT oe (©oRepeting Snamerts : Papin suri ae and ped ven & Siew y i Wi ee, a Ph IIE get eens rego canner se tr toe te eT ewe, $0 in tatan, ne Her, nies Hare i not Sat Shek mi be sipped. Flow SSiettsanowrn #2 Example 44 i sccarsing 10 80 Some examples othe statement are ven below, 1 ‘peed = = 100) ‘coupe is egal to 100", ‘There only one statement the if statement bck, there Tepito jock, free at ments < 35) t cout" Fares = fates « 1 be cndtn ew (ema ess han 9), ame ‘nov wearisome tM MS ge, namie 42 ‘Wa a ogame geo wo hen mabe Aria ie ies ace ren 5 oe boron cena tage ‘ty coment ap he So somes = oe ; sen ‘ota [== Sorgen reIs ES wenn cy cy er oie = | Seer. ewes: Se 3 The if....else statement ‘The general for of thi statement ie eondon) t sttement- 1 ' 2 the given conto is tue tan statement is executed chore statement ‘xocutea. Flowchart ef bis stants shown fig. 45 ioe c tot s met t: eon wemeiese Dos penini eon be ne pn som tg EPs; . a ite suman ns 4 2 ge ne er (og mater» TF (a>) THEN. oad a HSE big = tere nd hd mabe, the re TF > bit) THEN big = as = ‘ ie ic 4 sara =o amber, 1) PROGRAM Made coin el man) t Soot shee tne ule oe mambo a> ir he ies We> he foe" number ei few: , Ir he amber iou 4 care orisiediconts ee cea amount = "cet pas 1. Panoot, 125 en za, Homes itapucase smd fo mae an 6 11 0% 8 sowed Devacp a programa compute pce 2 Aoi 1 tga be 2 Cope dic 82 — dae 4 ie <0 then pat ‘rot are net rea ate JBRS)I24 tm 0-25 + Ouput root 1, root. ‘S. stop seme a 2, Frio alos oa inate aguas a+b ‘Answers / Hints to Self Check 1 Ari 1 gabe pacha gant, 24.09 > 10 ten dsm = 21 tera daa = 0 4 Gonpte Cat = 7 * 1S (18 diet, 4 Ongar Cat Progra ied ae | rem hero moie; cout" Enter the values of coeff."<<"0"; — see es ; root Segtiuc tates oad a mmvors using nosed # statement tet nsec sh vara nto. 611 moana rent ‘sect i ma foot abhi: Ce ee number": Toe ee Hew ;: ements eh ben: nctager miter che po aw FS re mbes eget mater 76 4. Nested if Statements ‘ref atment may conan neo rere steers. a suchas, bey ae so. Ar erareo of ose erent shown boom (en = a, pipers a = = = a ae ; on 8 senenroemenes gi tee coll eo eg am Sd na ah a nognnr eee Semen oe psceets iin a = ae ne : I; Pace | ss nes — ’ Vat nna as : Welte HRA rune 413, : eo a = SS Sree aman ng ta mie ae eer i Fie = } The else if Indder ne student, given his marks. ite a program to epay the grade ofthe student oven (es Fovehar ot his exam ‘PROGRAM OS shown nig. 414 ms int arts; le Utmaho50 grace’ he Gtearts-9) grade ra 5000-03 rk | i sat |e cnn mreaor02000 |) a rtoreaerne | ser Sa | ee area lee l ‘The switch Statement Take an Weitere BR. ser check2 toa prog octal he nco {ar according town cea i $0001 wo 60000 s 2,001 12, ‘The snitch statement et the value of avon exprossion aga! @ et of ese 7? z se ‘when amatchis ound, astatorentor statements associat wit he “The gonotel form of hs statements wn a ssh Cexpreson) 0 a 2 ees is sion" tome ee eae ety eed i ae ca carps te Second iia treat ttm © pcx conan pase = : Tr seettoncan be ange orate Teepe oa persone terme Coe tn, {steno ilo secede beak aor at oa a ae ws, oc cts parte ese and canes srl oan ser : 1 grade represent A, Passe , srccendl: rectangle seurSetour color irosenotes Sectchoee) "ase gutceEntr the sides of the rectal = cins>sde=sdeds iemcuide ide treat em oy Bter the ras + cute coutc<"Bnter the sd of the triangle = Sinssap>bsoer fmlavbsenae mremmagtinab ee ime game aaa, ieee, a 4 7 The goto Statement TRS stoner ana contt upon Regnea Genet senat PH HN eg se bt label ean val vale name Ont oe statement "Sool statements pertaed by abn te flowing rare EY by ‘Acolon sapratas the label and he labeled sateen Example 414 i “Repetitive Structures (loops) | peop mats opeating sme portion 1m other a spected nb of nes, eee pcnganistoaMnarapatve operation (eopirg) Is ocheved ee Satan awhile ora donwhlle ora for statement fate carota ot he, ws ‘ett Scents commend tal ban ona sea Repent ences oon _— ‘Seeman mah 8 aS yey Pont Ineaion : In 0 epetve te tae ort he po fey Example 435 Sacre, come vans ae ase whieh oa prone fe conic’ curing ateruton ot Tapetve one the Ss oot ramber Src. ieee Aeon (0 Loop: Ase of staterents ave oxocted using ‘Sted many te wile thse sttorert ‘Seperence rogram (NEL Point: Thre ms bean ext pnt come ‘uctiop so rat oop ces no Became int 2 inc hen GOTO te 1 ae Ral san 2 up Resa C (100) on ‘3 Powcharot tis example shown ng, 426 PROGRAM {naman denn ten | Geena” mien |) ies tf incade itrean> td late “min La | i ro 7 : 4.11 The do Statement ~o 3 “rate ‘nce old main ' Boat sumsinambermen; Lorattconios) ' ionumber: ; a Enter ttl number be averaged :$ Enter 5 mumters 0 20 70) , a) ec Fara = "fet i teins) ofa ‘eure = ) nt et i ter & mamber : 6 Factorial = 720 om 3. Fowehen : Paoeaet arbi ominne ty 48 FE re or Lane — ‘capabilties that are not found in other loop constructs. saasitons ese Site 7 for (i=; #<10; i++) , 1 sty evntim tcaes tt ne of ho i itiazod 0 Iinaroments 2 a i remains less than 10. The: op tos ho lop ar repeated a8 1000 08 outce"Ener the ae of "5 or tment ert oop index Intalized outside the 1o0p. ome He de eto og #010 eotce"Entr the number of ems ‘a0; oes ee, for (iel0s in) m= { £ mae statements; Jortahinmies) ! } i “orp wih ntizaon of oop index and increment outside the for loop is erm txt; foro fect 2 ist rany, ae nae heen ainingy ! ; statements; coutce"Sum of series: “ccsum; sem um we 1p wa i ; e 7P Mh tteaton ot op index, loop condo & increment outside the for statemen le tis Ran: Enter the value of 05 rer the numberof ters : 4 ‘Sum of the series : as21095. 454 The comma Operator Wie now: fn 40; bss canbe wren as b Jo Ue ot tet: ony t ; {se be raat sein. MERA AON May ve a, Example 419 > for Wott it0 tony 1 1 1s so posuble 12. use expression Inthe Assignment salman ae [cxsement sectena: For exrnle oO a eoe a aube :* Jor was Bit: 4305222) 4.15 The break statement Sometimes © progiammer may wish to ext he loop even whan the ancton s rue. This is possive wih the bret satomont Weave ea ee Steven io en tom a switch Beck Ths may be used in any pe eee ‘Sowing 436 ‘cutee Prime mumber” ’ Prime number Veron bres gram Bw moment mL ou I Be 60 he message “Not ape numba” ed ana the cia breaks ut tha while Wp. In hese ope, break aes Te matte the ane oop ony (14) cs) Example 421 S| sae sied rie Le i pros Beoran fron pr oor brs ang, 0 clude include sold maint) ‘ int romps conteeendlcc"*"ccendl Jortrow=ljrowexSirowes) t coutce"" {foriplas=Ipilusc-rowplust+) coutccendl; Pinctadeciotram hs or a include conia te a) Merges ho een na ret tee a et as pg se void main nr Pn a proces to prosk t ond {) tunaon U5 Int wine st es nt Hutto btn ster reenter ‘outce"Enter the mamterof pra ines ‘lnm: camber is pie oF Sorirowat iro t ar wine cade tren (tions) Mor pecig Sect Seniot pines snes aclu spree SelehicroJoe) No et hap comes ‘iat, i orhoosttoaih) Horie ball utente a mamber cuts"; ane he ne yin m2) , to) st coutce'Not «prime number"; , sche sue outecprime number”: (ea a 2 hat ‘na eaam,# he gv number fe vee by any number tom ‘unos he rogram delays a massage tat he rumba snot pine and ex owam atti eaured by ex) clon, fro) sore cont sn ovale - a HER Sayan we tls satemenn est ena Bi none ofthe . se Maa Second sete statements ar on ae omar ses ; rere Oe an toxin cote? * eter tetas stm : sib the output ofthe ae coat ccm oe oo ae Bone he above Gir aas = itch sntement can be used 8 incase of ogical operators us * Pare, 8. Remaatal "¥e5 0 oops, namo, ‘orden corte and our ne output of the following code? + bandon prey onctonna ga ef seaarnene cana aot te wit ns FS In counter, conttlled loop, we know the number of times the of the lop eg ™ freee Eamteoe eee ea 10 white toop, conciton |S evaluated frst, Theretore, ofthe Hoop maya 1 wll (meny Sneath et Band kw a irpation is evaluated atthe end Ther con ints steno 5 De beak statment causes ext A tamaltnesensioe 8. om th imermos oop containing 6 fen apa D. atthe are Wt et ote ong cade» wi ia tains ‘ere con a aw 8s ar BO ta ae —

You might also like