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

Unit 3

C LANGUAGE NOTES

Uploaded by

S
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)
33 views19 pages

Unit 3

C LANGUAGE NOTES

Uploaded by

S
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
You are on page 1/ 19
Uma 3 ConTRot FLow : A_Decision Maxine 4 Bran cHin& ae = “used Pow deciston making Purposes - —— - used +o evaluate one oF more conditions — Es make the “decrsion whether +o €xecute a Stare set of Statement oF nob - emia Type ES OF Conn AL STATEMENTS. 4. (x? Statement :- zp expression ts +rue then it executes the Statement otherwise yumps to hext thetruction - — zt checks whether given expression is boolean ov not: = SYNTAX iF (expression) “Statement 4 5 & Statement * 2s = - 6g: F a void main (9 - int a=5,b=6,¢ § = we C= atbs o print & ("Execute me 2) > OUTPUT: - Fuecute me 1 “\\\\\ Fz include < stdio-h 7 main () : int 4715 , b= 20; (bea) printf ("6 ts greater” ) 5° a= 3 OuTpUuT b ts qreate™: UF ~y [a - else Staten 3 co : - Tt ie used 30 that we Can Check an “| condition s clepending on the outcome of any es | Condition we can follow appropriate path —T SYNTAX ts ie (expression ) Statement 1 5 Statement 25 _. g else Statement 23, Statement 4, next ~ Statement . ~|a2 expressfon js true then Statement 4 A statement 2 wre executed otherwise Statement 3 S statement 4 ave executes) void pmain CD a | 3 | Int marks = 505 if (marks = = 40) | pant é (* student is pass”) s | __ else 7 ae , pantt (“Student is fail”) 5 jy 5 \ 2 : OUTPUT: - student iS pass. \\ -\\\ FaoarRam ‘10 #inD Opp Or Even Num@éR:- LE include int main () int number 5 pzint& (“Enter an integer: "J 5 Scan k ee — & number ) 5 tf number % 2 ==20 . ? print F ("%d ts an even Integer. , : number ) else g print F Cited ts an odd integey- 7, | number_) 3 \ oe I =a) ametuin O 4 | LOuTPUT Enter an jnteger : F = F te ae odd Integer - 7 a >. Pagano \ multiple Condition - T+ fs used execute SYNTAX =: TB Ceondition 41) —_ z Statement -1 5 else. 1 (condition 2) ff Btatement-2 Z 3 Else. ff Condition 3) ~ Statement -3 5 else 12 (condition 2) Z Statement n ia s else 3 default - statement 4 Statement - 2. FE include .< stdio- rs 53! ear] = = Ea a ieee eet FF include Votd main ©) Tne number = 0 3 clrecy ()5 primeé ("Enter a number : eee Sean f Gs pcke Pics numbex) > a tE (rumber == ]0 ) a print F (number is equal to lo”), 4 —| else 1£ (number == 50 )) - | paint F ( “number ‘3 equal to 50” ) 9 else 1% (number == loo): print k number ig equal to loo” ) | G _ a else ~ print® ( “number fs not equak to 10,50 exiee getch (do g s iz FF include mnt main C') int £5 20," {fe (225 ges . 4 Ppa (12 is wo 7G ‘ 1} OT elseif. (#£==!15 ) j Ss prink hf C# 2 is is “Do § _ elas 72 fxs = Ze) - : Q pint & ("a ts 20") 3 % - dese ? renee Cha TS, noF present” ) > Aa wy, Switch STATEMENT: ae aoe nile exe cane options we have oa ne_option Pum the is available 3 We Can Use Switch —\ gtatement. — _ ~| SYNTAX I> = = a Switch Cexpression) —— = tase value f= Statement [bteck-4 S | break 5 Case value 2 % Statement [ blocis - Cig break 5 : case value 3+ Statement [block -3 5 ; break 9 default + - “Statement | block 5° break » 4 ~_=[The Expyessten Following the Keyword ~__| Suiteh must ‘yield an integer value » It must | be integer constants I?ke 4,2,3 - ~—=| The Keyword “case” 19 followed by > integer or character Constant, each ~_| Constant in each must be different From —__ | ait the other - ie ~~ |Fivet” the integer expresston following the Keyword Switch fs evaluated The value —————————————— Ee Pag tg ‘Seanched against the Constant that Follow +he case Statement : va lues _ [When a match fe Found the progvam executes —\#he Statement following the Case -- IF Tino match ts Pound with any of the Case — | Statements , then statement Following the default one executed - 3 FE Tnclude setdtos h> main CD t 1 | tnt 5 : [ prmt® (“ple- Sater ano ber"G $5. ")s Beant ("“%d", Fa)S Switch Ca) / y LEE LL Case 1: print F (ign Choose One nd 5 break > case 2% print # C you Chose two " DE; break 3 | ; | { Case 5S + nee (raed chése. five "D5 Cans default + printe 7 “aavalid Choices Enter a no. bet” 445 ")s break 5 ae ¢ : 2s OUTPUT . [please enter a ho hei 44523 = ——| you. Choose. Three : = i ae ase! _ Pe onan | - - : “kK ALLL I |8 a 3 lines of Code only - 7 eee _ Suppose that you have -to” ‘pt = Lthen yYou-heed to write int table oF 2 jo lines oF Code using Loop Statement , You Can deo it ky 3 WHILE Loop ;- | SYNTAX +: Variable Initialization 3 while (condition ) &q:- ink R20 /_whila (x <5 10) ~ Statement 5 Variable, increement or decreement Eqis Htt ov MW~ OF KER 5 I+ ja an entry level loop Statement -e the Condition tg C@valuated Fivst F yh it ig true then body oF loop fs executed [AFtex executing the bedy oF the. loop , +he Condition is once again evaluated 4 if iF ts true , the body is executed once again: _ Continues [The process of sepeated execution of loop _ until the condition Finally “Become: False { Control is transferred out of the - _foop- # include < 8tdio-h > fe include: void main ¢ ) int % 5 | A while. rerrie Sea ey ey 4 = = output Se 123245 67 8 9 fo. fai: Proaram To Reverse Tne Numer - - : SESE FE inélude < stdio-h> int main C) | int n , Meverse=O , wemaindew 5 int CC Enter an integer + zy : Beank ("HA”, Sia) 5 —-+ = while (n |= 0) i aa ryemainder = n% 10. 5 —~_| wreverse =a everse *10 + vemainder,’ n [= Betas] print z (Reversed numbex = %d” -veverse ) 5° ___ netwen 0 $ r «| Expraination : F Suppose we wane ye verse Gi 26 n a }=0 ; a nie Veverse — (n%, 12) -. - [rev * tor yem\— 4. (26 True 26 % 10 onlot 6 — R= 6 =6 — __2. Ine to = — L =| 26/10 ‘True 2 == b R= = 2 + S a | : fata aul 2 4 ss ; i > = a \ ZR iDo- Write Loop:. Ss —~ |BYNTAX a : ia —\___vaviable initialization 5 oo ad ° - 7 ~ ae] Statements 5 =a Variable incveement or decreement 5 Es while (condition) 5 - Do- while Joop San exit Controlled loop [Btatement - =| Body of loop fs executed first 4 then the Condition fs evaluated .- IF it 's +eue then the body oF loop fs executed once again - = |The process oF execution oF body of loop Continued until the Condition Frnally io becomes false & Contvel is transferred to the otatement immediately after the loop - by] progvam to print ten multiples 0F. S&S FF include “ tt include < Conio-h> votd main (> (fy mt a, fs Az5bes ~~ bets AT ae lf print FCA \E”, ati), Botts ~~ 3 [ere Son Tae re ses 1, 2, 2, Be, | getch Od a | BS, 40, +8, 50 | 4 ok_Loor ~ ByN TAX | - ae : Inet fr C ‘initialization y Cond”? 3 _inermnt [decerant} \As\ 4 Statements 5 aa = z 7 : i+ tg an entry Controlled looping Statement - In this loop , move than one variable can be tnitialised . ~\teee actions can be taken at a time I'ke Vantable. inittalization , Cond” checking 4 increement] decrement - ~\ar 18 move conerse & Plextble than othex loops - . yt He include = ie HF include << Conto-h 7 Void main (2 int 2% 3 g for (x4 5 %K<=10 5 oc ++) £ 7 + prunth ("%A\E”, ~)3 7h 4 | getoh C9 5 t——~__| : + pesca a (tess - * | OuTpUT je] proarane fer write roultiples. of Any number include + Gobesuuvcas , be events 8 enh te oF een — [16 cod er Sar De Sail aheg 1¢ — ie eres ey ag La | GO. To. STATE MENT [t+ Glows us +o +vansfexr . C Program +o the eee SYNTAX. a east ce gS goto Tabetaxt 0 State ment 5 ) "When hes “goto. eraeqen fs “encoupreved” the control of the progtam jumps to Sabe 4: Caries) a gtavts executing | the Code. i : 7 €4:| FF include &) 5 Z : vetwin O 5 4 OUTPUT 4 2 3 - 3 a

You might also like