Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
19 views
Module 2 - Control Structures..........
Uploaded by
Anjali Tiwari
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Module 2_Control Structures.......... For Later
Download
Save
Save Module 2_Control Structures.......... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
19 views
Module 2 - Control Structures..........
Uploaded by
Anjali Tiwari
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Module 2_Control Structures.......... For Later
Carousel Previous
Carousel Next
Save
Save Module 2_Control Structures.......... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 55
Search
Fullscreen
ESTE LIE * Introduction to Control Structures, * Branching and Looping Structures * Switch statement * for loop, while loop, do while loop. © Break and Continue 2.1 Ordering a Solution in a Loop |i programming we need to sometimes control the flow of operation other than just the sequential statements. In this case we need the control statements — Coptrol statements are classified into two types viz. the ae statements and conditional statements, Merative statements are use to Perform certain ‘operation repetitively for certain number of times. In C we have three iterative statements viz. for loop, while Statements for a given number of times: Conditional statements are use to perform the operations based on a particular condition i.e. if a cofiion is true perform one task else perform another task. In C we have two conditional statements namely if-else statements and switch-case statements, Conditional statements are also called as selective Statements i.e. these statement select a particular Statement to be executed based on the condition, In the subsequent sections we will see all the iterative statements one by one in detail. We will be writing only the Pseudo code type algorithms from here ‘Snwards. For some program the stepwise algorithm Will be given for ease of students to understand the rogram, if statement, if-else statement, Nested if-else, do-while loop, Iterative statements are also called as repetitive statements as they repeat a set of Control Structures else-if Ladder 2.2_C- Control Structures for Iteration 2.2.1 for Loop For is a iterative statement. Itis used to repeat a set of statements number of times. The syntax (method of writing) for statement is given below {for(initializations; condition; increment / decrement |] lupdating) The sequence of execution of the for loop is such that the initialization statements are executed first. These initialization statements are executed only once. They are used to initi e values of les. ‘The second step is checking the condition specified. There can be only one condition. if more than one conditions are required they can be combined using the logical AND, OR operators. If the condition is falseProgramming (MU) the execution of the loop will be terminat execution will go outside the braces of for loop, if the condition is not true. — The third step is to execute alll the statements inside the curly braces. These statements will be executed sequentially. The number of statements can be of any count. There can be another control statement if required inside one control statement. — The fourth step is the increment / decrement or updating operations. These operations are not necessarily increment or decrement operations, but mostly these are increment decrement and hence called so. We can update the variables over here before starting the next iteration of the iterative statements. Finally the control goes back to the second step. As said the first step is executed only once, the steps that are repeated continuously are the second, third and fourth steps. After the fourth step the condition is checked again. if the condition is true the execution continues, else the control goes outside the for loop ive. the curly braces In the fol Using the for loop. sub section we will see some programs 2.2.1.1 Programs Based on for Loop Program 2.2.1 : Write @ program to display the word “Computer” five times using for loop Algorithm Step! : START Step il Step ill: IFi>5 THEN GOTO step Vil Step IV: PRINT "Computer". StepV ita, Step VI: GOTOstep Ill Step Vil: STOP. ‘Note : Notice the right shifted statements in algorithm ie. Step Ill to Vi. The shift indicates that these statements are in a loop or are to be executed multiple times. ed ie. the | Flowchart Yes No Lay | = Flowchart 1 Program #include
#include
void main () { ——————___ int i; | elrvert); forfi=1;i<=5;i+ +) { printf(*Computerin"); } getch(); Hi ps Output : ‘Computer Computer Computer In the above program we have used the for loo? variable ‘7’ is initialized to 1 in the ini statement. In the condition statement it is © woProgramming (MU) eae eee the value has reached 5. if not reached then the control enters inside the loop i.e. the curly braces. — The condition we have put is i<=5, since the value of | will vary from 1 to 5, Hence the statements inside the loop must be executed in all cases when the value of i is less than or equal to 5. This makes the conditional statement to be i<=5. All the statements inside the loop are executed. In this ‘case there is only one statement i.e. printf() to display the required string. Finally the increment decrement operation statements or updating statements are executed. In this case the value of ‘is incremented to 1 Thereafter the control goes back to the condition statement, and the loop continue until the value of ‘' reaches to five i.e. five times. naan eee Program 2.2.2 : Write a program to display the first ten natural numbers. Algorithm Step! Step: Stepill_: IFi>10 THEN GOTO step Vil. ‘StepIV: PRINT. Stepv: i=i+] StepVI_: GOTO step Ill Step Vil: STOP. Flowchart Winclude
void main() 4 Explanation : In the above program we have used for loop. The variable ‘i's initialized to 1 in the initialization statement. In the condition statement it is checked if the value has reached 10. If not reached then the control enters inside the loop i.e. the curly braces. In the curly braces we are printing the value of‘ itself, hence displaying 2 10 10. Write a program to display the first n natural where the value of n is taken from user Program 2.2.3: numbers, Algorithm step! Step: Stepill = Step IV 2 START PRINT “Enter a number". INPUT n. id.StepV _: IFi>n THEN GOTO step IX Step VI: PRINTI. Step vil: i=i+1. Step VI: GOTO step V StepIx STOP. Flowchart : PRINT "Enter a number” Flowchart 3 Program |#include
#include
lvoid main() { int isn: elrser(); print{("Enter a number: "): seanfi"Fod" o aS Sw Explanation : In this program we accept the value from user, using the scanf() statement and take the value of i from 1 tothe, number. We are displaying the value of i, and hence displaying the natural numbers from 1 to n. Program 2.2.4 : Write a program to find the factorial of number. Algorithm ‘STEP! START Step Il + PRINT “Enter a number”. Step ill =: INPUT n. Step IV = 1, fact=1 StepV — : IFi>n THEN GOTO step IX. StepVI: fact= fact *i. Step Vil iva Step VIll_ : GOTO step V || Step ix: PRINT fact StepX : STOPWC Programming (MU) Control Structures Flowch: i} Output : [Enter a number: 4 [Factorial of this number is:24 Explanation : In this program we accept a number from user in the variable n. We initialize the value of i ta 1 and also the value of the variable fact to 1. Remember, initialization Part of the for loop can have multiple initializations. Update or increment / decrement operations can be multiple. But the condition statement has to be only one, if required to be combined with AND / OR operator, PRINT "Enter a numbort — Now we keep on incrementing the value of i and ‘Tultiplying this to the variable fact. Hence first time the value of fact is multiplied by 1, then by 2, then by 3 and so on. Thus we implement the logic of fact = 1x 2 BAK sora Me — Note, the value of fact is initialized to 1, because it is to be multiplied by different numbers. Hence if we don’t initialize it, some random number will be there in the variable fact which will be multiplied by these numbers Fil art 4 i.e. 1,2,3... Also we cannot initialize the variable fact to ©, else i will always be multiplied with 0 and result will Program always be 0, em #include
a #include
Program 2. ‘Write a program to display the multiplication void main() table of a user entered number. The table must be upto 10. { Algorithm | int infact; Step! + START. | elrscrt)s Step!l_ PRINT "Enter a number", | Prinf(Enter a numbe Step lll; INPUT. scant ed an); StepIV. : i=. forli=1 fact=1si< =n; “= Mact=1ji<=nji++) StepV_: IFi> 10 THEN GOTO step IX. StepVI =: PRINTn"X" | tacemtact +i m6 } StepVil : izi+1 Print("Factorial of this number is: d\n" fact; eae etch(); StepIX : STOP.WC Programming (MU) Flowchart : PRINT “Enter a number" Program #include
‘#include
‘oid main() { int in; elrser(); Print{("Enter a number: scanf("%d",&n); for(i=1;i<=10;i++) { Printed ted = Sean" (uiy, getch(); Explanation : In this program we accept a number fom urns, variable n. We niialize the value of | t01 an aay, keep on calculating the value of n*i, ut l the value of, equal to 10. These values are displayed in the mutipicy table format. ee Program 2.2.6 : Write a program to display fist nat ‘numbers. Algorithm Step! START. Step! : PRINT “Enter a number". Step ill: INPUT n. StepIV : i=0 StepV —: IFi>n THEN GOTO step IX. StepVI_: PRINTi*2+1. Step VII ie. Step Vill: GOTO stepv StepIX : sTop,v Programming (MU) 27 Control Stuctures Flowchart : PRINT "Enter a number Program /#include
|#include
oid main() { int ijn; clrser(); printf("Enter a number: "): scanf("9ed",&n); for(i=0;i<=n-lji++) { } getch(); printf("%d\n",2%i+1)3 Hi Output : Enter a number: 6 [Saas Explanation : — _ In this program we multiply the value of i by 2 and add to it 1. To start the odd numbers from 1, we have to make the value of i initialized to 0, and hence go upton = 1. Since we need a total of n odd numbers, starting from 0 when we reach n-1, we have already covered numbers. Program 2.2.7 : Write a program to display odd numbers upto n. Algorithm Step! : START. Step Il PRINT “Enter a number" Step ill: INPUT. Step IV 1 StepV —: IFi>n THEN GOTO step Ix. Step VI: PRINTi. StepVil : i=i+2 Step Vill: GOTO step V StepIx STOP. Flowchart : PRINT “Enter a number 7 i> Flowchart 728 Programming (MU) Cont Spee? #include
#include
void main() { int ins. elrser() print{("Enter a number: seanf"4ed",8n); for(i=si<= { +=2) printf("%d\n".); } getch(; } Output : [Enter a number: 10 Explanatio In this program we increment the value of i by 2. As already discussed it is not necessary that only increment decrement statements can be written in the updating statements; we can also put some other ‘operations like the addition statement written in this program. The condition checked over here is that i must be less than or equal to n. As it is specified that the odd numbers are to be printed upto n, we want the value of | to reach maximum upto n. TT Program 228 : Write 2 a program to calculate and display the sum of first n natural numbers, (ers Algorithm Step! 2 START. Step Il + PRINT “Enter a number", Step lll: INPUT n, StepIV: i=1,sum=o. StepV — : IFi>n, THEN GOTO step ix. StepVI: sum=sum4i. + GOTO step V, + PRINT sum. 1 STOP, Step Vill Step IX step X Flowchart : PRINT "Entor a number Flowchart 8 Program #include
#include
void main() { int i,n,sum: clrser(); printf("Enter a number: seanf("%ed" &n); for(i= { si<=nji+ +) sum=sum. } Print{("Sum= %d\n" sum); getch();WC Programming (MU) 2.9 en eee Output : [Enter a number: 10 Sum= 55 Explanation : — Inthis program we are changing the values of i from 0 to n and in each case we are adding the value of i to sum. Since we are adding the new number to sum, the void main() { int insum=0; clrser()s print{("Enter a number: "); seanf("%ed" &n); for(i=Lsi<=nsit +) sum must be initialized to 0 as done during its { declaration. sum=sum-+i*i; — Hence at the end, the sum of all numbers from 1 to nis aes stored in the variable sum, which is displayed. ) print{("Sum= d\n" sum): Program 2.2.9 : Write a a program to calculate and display getch(); the sum of the square of first n natural numbers. } Algorithm Flowchart : Output : step! : START. Enter a number: 5 Stepil : PRINT "Enter Sum= 55 ee ad = In this program we are changing the values of i from 0 nN ade ton and in each case we are adding the value of 2*i to °. sum, ee ee “we — Hence at the end, the sum of n even numbers is stored x = in the variable sum, which is displayed. StepVI_: sum = sum + Program 2.2.10 : Write a program to display first n elements me of Fibonacci series, Step Vil: i=i+1 Semcon Note : Fibonacci series is a series wherein the first two % elements are 0 and 1. Thereafter the next values sagt ¢ PRINT sum, sum = sum +i are ee ang a two elements. Hence it ee cr can be said that the series is Teis4 0.1,1,2,3,5,8,13,21,34,55 tt | algorithm Step): START. Vu A Step Il: PRINT "Enter a number". Stepill: INPUT. STOR Step IV Peweners StepV : PRINTa,b Step VI: IFi>n—2, THEN GOTO step Xil. Program Ps Step Vl: c=atb. incl ; eo Step VII: PRINT c ‘#inelude
stepIX : a=b,b=c. SF fecttownieagewero Me ser oe saom + oro sepia: STOP, owhart: nen); Print Eater« number": sani ‘rin Fibonacci SeiesinO nla}; fori=l:ic=naiit-+) ) teh penne ‘Output Explanation = We fst diuplay the values © and 1 i.e. the first two elements of Fibonacc! eres. Also these two values are Intazed in the variables a and, tm every eration, the next value Is calculated and stored inthe variable ¢ and is printed. Also the values of 3 and bare updated accordingly ke. the latest two ‘values calculated must always be in a and ~The condition statement ofthe for loop is important this case, Since the frst two elements are already Printed the counting of printing. the elements of Fibonacci series in the loop must go only upto n-2 18 ‘wovalues less which ae printed outside the loop. Program 2.2.41 : Vite a program to calculate te value of he folowing series wc Proaranming MU) Seow F thumee SBEV: IFAD 0, THENGOTO step Seow s0m=90m 174, stew 2 Sepvil : GOTOstepy. Sepix = PRINTUm seepX 2 STOP. Flowchart: nth brogram we have taten the sum variable as oat ‘nd itetaed to 0. The because the result of ts | expression hast bea fraction value. And the terms Fe toe cactated anc added to ths Sum, nence | ayo aeother imporant ing Swe have weten amcsume LOM ntead of sing 1. we have wed 19. | se wewe nae witen dover ere the et would sways be 0 Reese for ainteger and even as | steps reat awaysO ie the gate, a_—erveiie ee ceeeer Program 22:12: Yea payer cate be va of thettoweg wren 143 of ai Tao \ meets man | sme | som fwW :sekbeedames PRINT “Enter te vals a Step: ion THENGOTO step : see + fatsfat*i tehdebe ad sums tum fet ‘Aorithm sep sie ate step Vl SOTO sep Sept: ORT “enter the value of se = rear Step: INPUT, | stepx + stor. weeControls Flowchart 12, Program Program #include
#include
void main() { int imfact=1; 9; float sum elrser(); print("Enter a numbers "s scant "Ged &n); fort { fact=fact*is nit +) é aout 1-0/fact sue ofthe series is:%0 sum) ) prin The geteh() ‘he factorial is calculated for every term inthe vag fact. The previous value of fact 15 just updates multiplying the next number to the previous ror example ifthe variable fact has the factorial vrven mutiplied by 5 (the resultant the fatny ing logic is same as the program 2.2.11, Rem: ite aa program to calculate the sn wr Program 2.2.13 : tn angie using the fokcwing soriae for x 20 th emg radians. : " ye ee sinx=x- 3j 5] ~7! nt ‘Accept the angle from user in degrees and display the rex corect upto 6 decimal places Algorithm step! : START. Stepll + PRINT Enter the value of x in degrees". Step Ill: INPUT. stepIV. : x=x/180* 3.14 Step: term=sum=x. StepVI : i=1,fact=1, sig Step VII: IF term < 0.000001, THEN GOTO step XIV Step Vill : fact=fact*i*i-1. StepIX : num=x, term=num / fact StepX — sum=sum + term * sign. StepXI sign =sign *-1 Step Xl: izi+2 Step XIll_ : GOTO step Vil Step XIV: PRINT sum. Stepxv : stop.Flowchart PRINT “Enter the value of x in degree" =x/ 180° 3714 term = sum fact = fact*i* num =x’ term = num / fact sum = sum + sign * term sign = sign *-1 yy Program #include
\#include
'#include
oid main() { int i, fact=1,sign=-1; float x,numerator,sum,term; celrser() print{("Enter an angle in degrees: "); seani("%ef" &x)s x=x*3.14/180; term=x; sum=term; for(i { 3;term> =| fact=fact*i*(i-1); numerator=pow'(x,i): term=numerator/fact; sum=sum + sign * term; sign=sign*—1; | } print{("The value of the series is:6{",sum); getchs i Output : [Enter an angle in degrees: 45 ‘The value of the series is:0.706821 Explanation : = The formula given in the question is for an angle in radi is. Hence we first take the angle in degrees from user and then convert it in radians. — The first term is x, hence the value of x is first put into the variable term and hence into the variable sum. The variable term is used to calculate the value of each term and then to be added in the variable sum, which is used to calculate the value of the entire series. = Inthe for loop, the value of iis started from 3, as seen in the series. The condition is that term should be less than 0.000001 i.e. term’s weight must be less than the sixth decimal place and hence allowing the change in the sum upto sixth decimal place. = The factorial is calculated for every term in the variable fact. The previous value of fact is just updated by multiplying the next two numbers to the previous factorial. For example if the variable fact has the factorial of 3, when multiplied by 5 and 4 (i and i-1), the resultant is the factorial of 5. ¥rogramming (MU) ply calculated BY Using the powl) sim der file math-h ed by dividing the NUM! the numerator 15 function in the hea i calculat ator BY he term i factorial. Then this term ith proper si8® js initialized nged bY ss added withthe sum wi mis used for this, The SE? jon its sign 5 cha! ever ee ey He net nth? ieee eee e the factorial and exponent series the terms require fed by two W. Fits PFE im to caloulate the sine of for x as the angle in jous value. increment vio vam 2.2.14; Waite @ a rograt Prog 1g series an angle using the followin x +07 radians. sinX®X- 3 s accept the angle in degrees and value of from User Algorithm step! = START. Step il: PRINT “Enter the value of xin degrees and the value of a". stepili INPUT StepIV: x=x/180°3.14 StepV: term=sum Step Vi Step Vil: IFi>n THEN GOTO step XIV. Step Vill: fact=fact*i*i-1. Step IX: num=y, term = num/ fact StepX —: sum=sum + term * sign Step XI: sign= sign? 1 ‘Step Xi! i+2, Step XIII: GOTO step Vil Step XIV: PRINT sum, Step xv: stop. Flowchart = { Program [#include
|#include
|#inelude
void main() Faortoann Freie ti 0 Flowchart 14 inti, n, fact=1,sign=—1; float x,numerator,sum,term; clrser(); printf("Enter an angle in degrees and the value of n: "); scanf("%ot %dl",&x,&n); X=x*3.14/180; term=x; sum=term; fori=3:i< =p,WC Programming (MU) Control Structures. — ‘numerator=pow(x,i); tern=numerator/fact; sum=sum + sign * term; sign=sign*—1; } print{("The value of the series is:%f",sum); getch(); [Enter an angle in degrees and the value of n: 45 10 1e value of the series is:0.706821 Explanation : The only change in this program compared to the previous one is that the value of n is taken from the user and the value of iis varied upto n. a Program 2.2.4{a) : Write a program to calculate the sum of series xx/2I4x/3Lx/4.....X/n! Program 2.2.15 : Write a a program to display the square, cube, fourth power, .....n” power of x, where x is an integer taken from user. Algorithm Step! : START. Step: PRINT “Enter the values of x and n”. Step ill: INPUT, n. StepIV : i= 1. StepV —: IFi>n, THEN GOTO step IX Step VI: PRINTx. Stepvil : i=i+2. Step Vill: GOTO step Vv. StepIx —: STOP. Flowchart : [include
PRINT "Ero vaio #include
void main() { inti, n, fact=1,sign: | float 2,sum=0; | elrser(); printf("Enter the value of x and the value of n: "); seantl("96f %al",&ex,6n); for(i=1;i<=n;i+ +) { fact=fact* sum + sign * x/fact; sign=sign*-1; Print{("The value of the series is:%f",sum); getch(); Output : [Enter the value of x and the value of n: 3 5 [The value of the series is: Program j#include
{void main() K float x; elrser()s print("Enter the value of x and the value of scant "9 od Bex.&n); forli=2;i<=n;i++) { printf" raised to %ed is G60" x,ipowlsi))s } getch(); Ub eee Output : Enter the value of x and the value of n: 3 Is 3 raised to 2 is 9 3 raised to 3 is 27 3 raised to 4 is 81 [3 raised to 5 is 243 | Program 2.2.16 : Write a program to display the value of 5 fort=1, 5, 10, 15, 20, ..100. | STOP s=s0+w+par | Algorithm Flowchart 16 Step|: START. | Program ee Stepll_: PRINT “Enter the values of 0, vO and a (ie. | #include
—_ initial displacement, velocity and | | include
acceleration)". | : Step ill: INPUTSO, vO, a Sapam SteplV : s=s0+v0+05¢%a i StepV : PRINT*2",s int; stepVI: t=5. | float s.s0.00.2: Step VII : IFt>100, THEN GOTO step xi! | clever); Step Vill: s=s0+v0+05%a*t*t, || Printfi"Enter the values of s0, vO and a"): Step IX : PRINTt,s | seanfi"%f Sf %f",&30,&v0, StepX : tet+s. | printeuSint sed” s0-+¥0-+0.5%2): Step XI: GOTO step Vil. for(t=5:t<=100;+=5) ‘Step x: STOP, bestControl Structures 1 99 5 127.500002 10 495.0001 15 1107.500021 20. 1965.000038 25 3067.50006 30 4415.000086 35 50 12255.000238 60 17645.000343 65 20707.500403 70 24015,000467 75 27567.500536 8 41365.00061 las 1 59695.000772 5 44227.S00861 10) _49005.000954 Explanation ; The values of 30, vO and a are taken from the user. The output is displayed in a tabular form with the Values of t and S separated by a horizontal tab (using the escape sequence “\t") The first value ie, with t=1, is displayed outside the loop, as it doesnt match the series of 5, 10, 15, 20.200, The remaining values are calculated and displayed Using a for loop wherein the value of t is incremented by 5 after every iteration, The new value of S is ‘aleulated and displayed again separated with a horizontal tab. ‘This loop is repeated until the value of t reaches 100. 2.2.1.2 Nested for Loop ‘for loop inside another for loop is called as nested for loop. When a particular operation has twa references, we Fequire nested for loop. For example if we want to keep a reference of row number and column number, then we can use a nested for loop Many programs based on nested for loop are given below. In this case the variable i keeps a track of row number and j keeps a track of column number. ee Program 2.2.17 : Write a program to display line and five such lines, Algorithm. Step! : START. Step it 1 Stepill : IFi>5, THEN GOTO step xit Step Iv StepV —: IFj>2, THEN GOTO step Ix StepVI PRINT "Hi" Step Vl: j=j41 Step Vill: GOTO step Vv Step IX —: PRINT next line character. StepX iva. Step Xl: GOTO step i Step Xl; STOP,HC Programing MU) a Flowchart : etch: ist -— } out: a ee i Hi Hi th Hifi Hi Hi Explanation : ~ The value of is fst intalized to, and the va oj also intialized to 1. The statement in the inner for prints the string “Hi” for two times in the same i Thereafter the value of j doesn’t satisfy the cont and the control comes outside the inner for loop, The next operation in the outer for loop isto goto next lin ie. printf("\n") statement, ~ After that the value of iis incremented. The value of less than 5, hence it repeats the same for the next a seen in the output. For this line the value of is gal initialized to 1, reel Note: Whenever the execution of a for loop repeats, initialization statements are executed again athe beginning Program This process is repeated for five times, Hence t same things is displayed for five times as shown nt ‘#include
#include
output. ae lvoid main() Program 2.2.18 : Find the output ofthe following prog” Program 2.2.48: Find the ouput of the folowing eT ( #include
int ijs ‘#include
elrser(); void main() fori=lsi<=5ii44) oo { ( ints clrser(); fori 1ii<=5ii4-4)BC Programming (MU) 249 Control Structures { Flowchart ; for( { printf("Hello "\: } print" \n"is " getch(): ) ar a fiawias
2, THEN GOTO step XII Flowchart 18 Sep + Program StepV IF j>3, THEN GOTO step ix ————— ; Hinelude
Step VI: PRINT "Hello" #include
Stepvil : j=j41 void main() Step Vil: GoTO step v { StepiX + PRINT next line character. Stepx : isiea, celrser() Stepx! : GoTO step i. for(i= sis =2:i++) Stepx stop, SE rieowciae neBF © Programming MU) Hello H 2 fory=1ys=3y +4) printi"Helle 20 Flowchart Helle Jello Hello Explanation thence the value inner loop shou id print the string “Hello “ thrice 's varied from 1 to 3, Since this isto for two lines, the value of iis varied from 1 to 2 Program 2220 : Wite 2 program to display the folowing Algorith Step! Step li Step tl Step iv Stepv Step vi Step vil Step Vill Step IK Step x Step xi Step XII 7 5, THEN GOTO step xi iF 171, THEN GOTO step x PRINT" +1 GOTO step v + PRINT next line character bisie. GOTO step tI, + STOP, #inclule
Hinclude
void main) { inte elrser(); forti=Control Structures 1 | u m un mn ‘Explanation : ~The inner loop should display the number of 1s. equal to the line number. Hence the value of jis taken from 1 to i, which keeps the record of line number. = Hence you will notice in the last four programs we have written, | has always kept a track of line number. This is just to make it convenient for understanding. —— Program 2.2.24 : Write @ program to display the folowing : CE ‘Algorithm Step! : START. Step: i=3. Step ill: IF >5, THEN GOTO step xi StepIV : j=1. StepV IF) >i, THEN GOTO step Ix Step vil: PRINT" Step vil: j=) 41 Step Vi: GOTO step V Step ik: PRINT next line character. StepX : izi+1. StepxXt_ ; GOTO step Il Step xl: stop. Flowchart : PRINT next line haracter leet 7 | Flowchart 20 Program #include
#in void main() { ile
int ijs closet) forli=1i<=5;i4+) { for(j=1ij<=isj++) Se rataProgramming (MU) printfi"*"): printi("\n") } ub Output Program 2.2.22 : Wrte a program to display the following for the user specifies number of lines lines Algorithm Step! START. Step: PRINT “Enter the number of lines" Step i= INPUT Step iV: i= StepV: \Fi> 0, THENGOTO step xIV Stepvi: j=1 Step Vil = IF) >), THEN GOTO step XI Step vil: PRINT Step ix jejel StepX GOTO step vi Step XI: PRINT next line character, Step Xil sitd Step XIII: GOTO step v, Step XIV: stop. For other patterns the flowchart i ad will be in similar Flowchart : ra | cI) | PRINT next line character isitt Fd Flowchart 21 Program am ee include
#include
void main() { int nsLF ¥F 10 Programming (MU) elrser(): print{("Enter the number of Tis scanfi"%ed",&n): ++) forj=1i< { sit +) printf"): printf"wn"s geteh() Output Output Enter the number of li Program 2.2.23 : Write @ program to display the following for the user specified number of lines ! | nlines Algorithm Step! START. Step il; PRINT “Enter the number of lines" ‘ Step ill =: INPUTn Steplv: i=1. StepV : IFi>n, THEN GOTO step XIX 2.23 Control Structures Step Vi Step VII IFj>n~i, THEN GOTO step XI Step Vill: PRINT” StepiX os j=jea StepX —: GOTO step vit step XI Step XII: IF |>1, THEN GOTO step xvi Step XIII: PRINT "*" Stepxiv.: j=j+t Step XV: GOTO step Xil Step XVI. : PRINT next line character Step XVII : 1-141 Step XVIII : GOTO step V. Step xIK : STOP. Program #include
#include
| void main() | { elrser()s print{("Enter the number of lines:"): seanf("%ed" Sn); | si<=mit +) { for(j=1ij<=n-ii + +) { printf" ")s } forj=li<=ii+ +) ( printi("*") } printf("\n"); } gerchOs ee Se aeonsreer feiet ‘Beaton ve apne tote | 00K: coTOneo eae meron thet to cuss itcen, | wee regmnnen ee 7 rogram 2228; 163 3 DOHEM dete nn | StS 091 PNT nee character. | Save tnemne tinea = ST Li perone teticres a ae mii ( Som esi nenerour 2 ts | ——— aan ) lrettcene | =o. heen || f= | Sor cnet eee _— 2 | oo ; |) Sh iteeeneee | O beta pes || mum, (ir Ge cere in te ape ) " seep 5 I ‘ ian _— froma | coro is ce | ee oi | te oe pin SS Sanh aie | oe rns. ee sna seo: jai | F =o [a geruencagty seer rinencmomem | OC mom fon me ce fa |: crboen : ue fonts rte, esicta te entre sen Ste oo nc mae ta, mm ees ia Som ricimecoose tim, || selene jose om | ? HS ise ngticemijt) Explanation soe | MBML = ipa. mencorospn | are serait | So | } ~ Howe nitro evs pop sate) =~ sroyen Co) ite, [emma | firaseamercrone xe ae stoma | me 7 som sj ) ot h pistes [ve ows :en) “ow I sn see isaac leer au ; So sy ltetaipetnss pee ies", a ied oc oo fe | se Some Hoe cnncromon nt ‘geen? ‘oom | ) : meet rane ane) | eoronewt yo bs fxjsticn oo St woe “ae || mo een asi ‘ oo ‘cee eto iso Shaws i> Ltn Coto wena = mee 28 onset || | mam sm fae te mabe ina vest Se ie | Fj ; (BR Shane | 11 ee meee niet i on) |
—a“—asereees_— ase rexnmt ia ponte cea | sn | Paps ies armen ‘Stop: IFi>n, THEN GOTO step XV eae _ | || mieveesereroe ne so wise, a Seo e/o\ EN COTO Rep Feomntam nines apaomnomervowous || SS on Step: PRINT) pea teeee ree: | ‘printf Enter the numberof lines" “ABCOCEA ee ones So sex + exon 4 soerevcen Sup: Porn caer ‘Step Het a ‘Step: GOTO stepv. jee “PRINT “Exner the number af lnes” supa sce sence vests saoeasact290) el wc reommnrs ot el » ee eg rmeucoTo ep 2 Igoe ehe) | aoa nl | ser joa THN CorO EPH ein seh. | ee ; Sree ni cer: coro" , et _geteht) see ps uruneoro stent ve [ae ai eo sm en | sa ae, aaa sor covet ABA eorajies ances Sm yoni coro ABCDCBA BEN mr ted a 8 ancoEDceA cule __ABCDEFEDCBA___ ment shit carson: Soin | noreetbe he Te Sara ge hve oe oe ee oe Tatar arate soph See Hence nthe above program we have eee print fchar lr): — Instead of the statement of previous program Pccecaon>= STSE| ere fe nin Frogan 2230 wine «paper © or Dean I hinge wer reat tne sie Es | rt ere aero’ fi seu es nimiennit4) ae =o € ‘Step: PRINT "Enter the number of lines” | eS. Step: INPUT { StepV : ist, k=t. int Sepv isn THEVGoTOstep ) Sept farj=lje=ij+ +) ‘Sep VII: IF j>1, THEN GOTO step x1 steph: Pi Sep: inset yerenanning MU) 7 SE ites tree wees = zs Disectiecn) |e oe carer mons See jaa, loa Se Semana aaah = ; Seca aS Soe =n a eae Explanation ove the rumbers tobe peta are othe ae ue fe, curn umber tod he be ae Inert every tne 2 ve ies. eee 2 spare variate Ln Fused t beep» oko he hunters tobe printed The statenent ein inthe valu of k nd then rare and ‘es space between the S40 number ee inde s4nke ) ae es oo KATEee. Cont tty a screparere tt ~ fe me eae cb wie s se ie onMLE. | rune Satan sem enn ee eg ae resem een | mm sino p ve se ec | ace ecient le lageticnist+) iiecori> pei“ mat ’ he nadine t ete faj=id> hi) Sets wins , oa Progam 2234: Wie « progam fo gorse fon inens ecm, oF pela oro wet ces mbt rte) | Rerueenien | mannsesive Ft atte geseoy ) es fh i | lesa i oe le | Beppaicireeel pe rlenaet—iay a || Sctrewsmteeoscees = | Seinen evened Crema inbe oad uate oie 222 while and do-while Loops Ip ine setenv seta ae nce een ttharbart mcs rly awe ape ot tet ne he stoma ae cet te ‘et int ee an we a te | aces pay se ou | pees kes eres a acer operate mmm |" hear artic ow stun R223) “ico townie bon Aaah how ee ae’ | aan Stecce int soto op ee wena wre, 223) da tition sown cove be goat i Be Soest nth secon vaste ae | Siemon Tastee wy aie =a saree i S| oo aassim te coiy te neces . one er op Tee ate we ws 0 ae bee one “im eo oe ose oa ee | fe spent sy ; ‘ | | statement 1! : sete || ie ) __ eae are et eeetel Bian ne cnoton a 7 en sl | eee Sacre es 0 | [it at | saa] th sndon ah ta of eareie noc etree op BH Sis genie cor TH fenton ‘ae the onion ot TH ee te te cor ovr the op. Hee th aT non nto re est er 9 omeatnaber he Condon the sta ted fre ion) ae | Tie onton re carl wil never et ie leop. hence te pom Parte coral ever ears aa te atatements ne loop arnever executed | ete rae Ft er || Condtin ne a8 ese oe. a 5) i i oe Sy ae The ats and ewe sn iar a i Taanene——| dl * wing a2t Programe Based on gowteLop nt ot “Eero amber ute. coro faim =—— PE en Seer ‘le vac t Seo oome "Smter coca ems res : ‘ono be ‘aga 2235 a gegen Sy tar ete sit 8 Seu Teron sep 2 seey: FissTHonsoTo nea step PNT sep 1910 feo: cro Sepik + O°‘naten: | Pe ys wl ce OH te | Teeeaite opie beak imags | remit tel | Te et ST a | ome were le 0 © bet a seme te | ‘ne gan executed ifthe condition’ tue | _—, Tiuamansecr ct | Prat oe | — pape EW Wins sregan Real | ses ea gh: ners amber ee =4 swt: aout, Kim pe oor F Sep: wo=0.nencoro wane ae SepW 5 Stennett wn es fo bev | srdsae ag | cniscien, || ew = ners | mt Sep = coroseny |e SP atop Hi sm + so rot, Sond aPrac dt, pat cs eae es ere or |Eesaeee Slaten Wehaesany ue slg ting te et of ‘urbe ing he umber en aia "amine An he mer cane by reno tg contre ie by 30 Tem itt tan he rd 3. THe um aed wen npn ve tne gh us, te he procs muied wth the gt evry mea det eS card " | Poms 2237 vee « pagan ode mim od | beat a eat ae end rant wn ie | Sem a | set ial pot ome utr ena eeiceman> ed || sete 5 sone re Sv recanen coop napa gto |= secs ante | some snes frie nn) sat ay “hileat=0) || sweet: coro nee aa(FncadeZaol> ince
id mand ke im adnan chee peters abe sn . | mmr ‘ er [sc ee | ei [Pasa iiss en «pega Sun tr proven 238008 1 Cumnoeree seth Te cartecottt ees near sora coos Spo: INTE samp * STOR ower ore aes ro ‘ it) er Sere amit, ec I “att Liaise | es | b |) ao = | Gears or | | Nettie \ j Z pen 2230: it 2 yn lB ate | Tee are war deal nt nx fc | = | ‘steph: PRINT “Enters number” | Stow sentpecemdtheermneans | <> Step: x24 10 | Supt conostepy | Spx: count =o. | on oanpectstiepro ae a= ‘Sup an: IF x6 0 THEN GOTO step pr 5 count count +1 7 = = neneto= z 2 rege po enor cane 828 ropa 25 w) memeanagencnce Mn me: eda HE OH dg aaa — iar et ace ‘ , eee ois fie ein rember gin bebe eal oven [Snore ei pt xoanton ~The tpt oe ed ate prt ‘ete ny fd amb ge aa a co eee nara any ba Eamrocr ice pct | seo: sptenneei0. puts non 30 ‘ Ieveuccsevenet Otis , nT eerae mum ie seve meh: ranaton hee aad the Prop 22h hm + pom cre a nae yee SEE esti Sie’ Ia Sep | comecoro ser Bem: Speen? ‘Sepik: Coro eprm poze suse mem poh $2 8003 Bt Roy : ecm pie (Facade Vide oni > jen > i i te ea i : : feimicmasiesy 2 rina} € 33 fan eee = on ftim = 908 ete 6 ace steonv epee Stepan + Gor0stenv Stepan: STOR,Yoo el a seta ) [Seceesys sence Saco ee ——— ear Sa ‘rogram 22.48: Wire OGM T eipay ony peer. a teow set pee cient a ‘Stop Vi: PRINT j + x1 type casted 10 chanem te strc eer eee ace esters HeneneeeetsCe ee coe 2 tea ser ten > ——— ) Tevaeel ie wneeeDR8S [E = ce EEE fo | come rogram 2.249 Wie apg cn um tae sit : oe monte |) Som Sh tre | sow nian | ae3 aan Program 2251 : Wee progam dap fm pate [Pinclade
Iincheconioh> kd mint) K els jcesitt) sea ajejeniae +) ‘ peo [a int: , wes sega t check Progam 3 pre 018 0 8 (nce d™ pinecone b> id ain amserene= gor ne pier be ea 8 slt=00 ( e=n500; pelt, frecsesrevere 104i > eo ‘ke i ech peewee’ ‘pat: fer «ber I250 [De reese numberi1321 ye) pl Pliodoe)s Net Palins rogram 2289 : Wee @ rogram call sremain dines 12-34 58=78 4 oo Dae incale
inca
jd msi) a seca oats = 05 prin Eee vale o sean ni fain 1je hice ‘ sensu (al D } rim = su) gael recemiah> (tino het Enter th une es; pao farenie=miey ‘ njeniceniiet) || t > t pint ) wins : or Oupat [Peete mater =a | 2 cee a | Pogam 22.55: it a Progam cake smoot es, [tens arate eet atone |#itcade eens amend Sao Po nthe Va of ad oh Seber remit iy mle aa sation dears emai i Out se he da Nes oe Iheoun = 2 ane te oven 2258: ie 8 pops ane ow ten 8 asco » 4 12948 posse DEDbeGeniestasee) t pei r reese) < it Re ehang #60) , rin = ie a , fe sai cnenie +) ‘ rie Re ha G+ 6 paca = ) rete b Sree or ot [erin ‘ c peace, eee manana caesar, os ‘ Sate ‘ wi | : aan) ‘ (enor, t ins 64 : | cas | : ‘count =eount=k=05 | a z b ma | a £ oat Et ae om aoa vor oun a im) f ai et foatiensit-) ( sia) fea Bo ee | ) 80s & beirtuasicndeey roars , | 22 Convo Sruetures for Stection |: wate me | Seeesrecnc: | SS i“2 ena necting 2344 Programs using ites Statement Prenan 34: Wies pone och tne er ees amo weve ty 0 ert sort so! ser spl + FANT ante sept: mourn tap + Wmad0« OTA PNT -Dse by 10 USER ot ey 30" wee: 50, at wen [Piecnac
| ert sept = sR steph PRNT oars umberBg Programming (au) Control Structures, Progr nat en step SINT “Enter a number? #include
step fi INPUT A. #include
stay x= 98, void main() StF y: IF n=0, THEN GOTO step xv, { oe 1 X=X+1, Copy =x, sum=9, step Fx step vil ‘vill = digi oe digit bx=x/10. wor xex/ See x + GOTO step Vi step XI + IF sum = copy THEN PRINT copy AND n= n= 1, step Xll : X= COPY step Xill : GOTO Step V. step XIV: STOP. 0, THEN GOTO step x1, * mod 10, sum = sum + digit * digit + Flowchart : PRINT Enter ‘agt= mod 10 sum = sum + dig eign? dig newto Flowchart 6 int sum digits clrser(); scanf("ed" &n)s Printl(’The ist of given below\n" n); while(n!=0) { atts ‘copy=x; sum=0; while(x!=0) x=N/10; geteh(); } Output : Enter a number: 4 153, 370 371 407 Explanation : Armstrong number. 99.copy ns Printf{"Enter a number:"); %a (The list of 4 Amustrong nuniber is a Similar to the previous pro loop keeps a track of numb Amustrong number given below gram only that the external er of values found to be WE haeoanageaa 1 To eg rina oy es a] ane agence ve vas a5 ||| potters Tilicee ence cuing oe nmaen ||) Reeve 47 | Deen orate en an [|| semi Ae fatannunee year OS yew100!=0 | Moser saya Ameena rater tne ||| joei00=—0 Spero oapmerynemameerne me ||| Tray ro, ropa 237 wan apopam mci erem’ | mats | s | po ; “ ar ramive”. Te isms aioe rae =e Sil the numbers are checked to be dive By the eee eeacine ca Fetes rier mee an exe ScteitipetstSectoerewcenaes aoe aaa secreted ee bean Lownie a = ome tw ck ica 2 eee a Se comer LJ ~ Sct La Seale |} & 7a Nescnen: zi : pass a |] 2 mon siuot SRT ont pt eae aa i) ‘Step: INPUT meant") i pal one ery i feomm | seep y= Wc THEN GOTO step i= t ee || me: enmetce men nr io tin Pe alan a ater ail, > a =mesg atone wes Aeon ap RIVE aie name. step + er. TRNPRI aa AND GOTO Hep: iin =2,THENPRWT Iw" ANO GOTO EDN ep: Fn THELEN "Three AND GOTO ep Step + (n=, HENPRT "AND GoTO tea sp: n= THENPRIT Si” AND GOTO tp x sep Hh: fn 1. HEN PRAT Sen” AND GOTO tp tp: a= 8 THEN PANT ht ANDO COT step ut tn yg ee b 1 ‘ 1 1 ee Foes nenrmnrne ao coro ie [|mrem: Tietsenonna-ene coo} tee Tp Seen | f =" Sern: Fan nena 80 cre se Bil Ei tet co aoe —s 96 mo coro Si Ms som «Fas nia ma 0 oo : Seon ee sep + Garon Smt: eg Fie Pinde
iid i » tthe tear apa "ssenaton The shove program i sid oil he tr (wh the operation at expire st eae rope,‘ra ttr he apertin o beproed | tenner dal cheese: | tts ne acters: taceoaed pon Dierece™ rm, eu iQue nf Reminder sev seen eft eval eke, sep , sex ec b ouput Ener opsaon fe psd pension = rnc twee ||| —— ‘orem 2358: Wine « popam wg ashore w || he oye cum msotrotenemibescoestyranion || n : er mat ee, + ms 63.2073 9, enna: rit Distnton’ schinl10) IF rks» 5, PRT sg Sra 6 ma cn £7. 8.013 PCa extnaton eer (Rovere ae are te ys sey a re, fi en | apy: n= EN Pt -O AND GOTO ep ‘ten ante fo wale he me 3 Eger ante reno ensranching Statemerns TEA, Contin, 233 ran We WI TEETH Or it ‘Ono, see ready 300 The ue ye ‘we have already the we of Me Tetevase, Let US 0 the a atte loop statements" | Zinue and breakin | ment neglects the statements ateny | __/ re beak sat he control outside erst ide Te apy the loon and tans 1] ghown in Fie. 232 | ‘41 shows the operation of Break tite, tase ements Le. | reach of the 1908 state for, while ang ie sees | wae seetntiizaion;cOndiNON; Ine don) | { } ig. 2..2(2): Operation of continue ‘statement in a for loop a c |Whto(conate) i porraton of continue (2) Operon ef continue Cotement (a while 1oOP ‘statement in a do-while loop Fig 232 Ave goto statement transfers the control tothe label Spectied with the goto statement. A labels any name {ven toa particular part inthe program. The belisto be followed witha colon (:) The syntax ofa goto statement is as shown below teak : ane Tp : beaks - cx piu: ) ee: gig. 237%0): Operation of break statement na for oe ra = svar : case 1 ins Ober 4 { teak 5 : | eae iaeene brea break: eet ° : case 12 pifDecenbe : : feet ; j whietondte Aelia Tvald ont suber) L, Ly ) | ech (eOperationot break (c) Operationofbresk | : ‘tataent ina statementin& loop ‘downielooe “ol Fig. 23.4 | ere enh mone ~ cominue statement also neglects the ster pat after tin the loop and transfers the contol bk planation ——]] Searing ofthe ooo for next iteration. The Fé 2 ea shows the operation of continue statement #2 single mpleneraton of witcha stateent the loop statements ie. for, wile and wit statements, —— oa to label label2: Isbell a | - goto label2 Wess OS ee eee Thus it shows that the label can be Before or after the foto statement and hence the control can be transferred to earler or next statements using 2 got© statement. ‘We ill be using these statements (especialy brea) in ur further chapters but stil let us see the use ofthese atements with one program each. —— 27) Control Structures. 23.47 : Wile 2 program to demonstrate the use of {0 statement. oR ‘White a program o accept numbers from user and add ther. ‘Stop accepting the numbers if the sum is greater then OF (alo 100 and pay the sum, + START = total=0 = PRINT"Entera number” INPUT total = total +n. IF total>« 100, THEN GOTO step Vi oro step + PRINT total stop. int nfotal=0; ler): (saan prin"Enter a number": scanf'%ed ns total =toual+n: iota <100) oto agi print(Total= Sed" ota: sete: [Biter a mamber6 [Enter a numbers? [Enter number 33, {Total =101 Explanation : cei this program, the label agnn is used besides the prt taterert The contin checks if the value of re total snot yet equal to 200, then it transfers the way Em Iremem seta pe enh sees eg i gest wo i recy dle eenmaet| te it ems) neha en ee Teme) Sect ae ey oar aie ; as or nuap ete heist reais ee dot Mt son re os yd enced we A SE ae |S wo tne ‘Seer eee oe oe roam ee a oo ner aa = ane Sea ; ac tg Na nar net elec than 100" AND «i~1 AND GOTO step | ebm oo | if Ee a mbes, step: i=i62 cand ns ‘step vill: GOTO step | im re oo | radeon ‘stapX + STOP, a ae res git HOW eh teow?) Carton ini eee A om : pring Naren an 3), } plete ) rs gerade sp sey step san Sto Sip oven: taianation are the ember nary tr gee nn 8 nbs aber srt coder ante wr © verte nonber oan, the vate of isda ‘Ts mambe net to Be coed a on 1 HE nba be ae, 234 Some More Practice Programs Fram 2320 wine @ pea tft GeO MO sane. sth Sp Se ep + RINT eer wonunber INPUT ert rThetgdons aster Sit ed «0A wd oe =O ct co ev ees corse ete a Ge ont Beer se, GD [ez /2 801 [eaoano Be etoot Henn Ee Kk tment intol nba: swoy fF fem med st 8 AND ey tne {2-01 HEN6OTO stom. pend Eero mabe) sept: homslen ean eA 2) Sep: coTOst9¥ Hk) Sept = PRAT Sepik + STOP owen: a7 7 tomece_/ ityste=) em GCD dost xe: ae pens GCD= es reeks b output [aero mies 25 bo (omega expansion: we start wth the ower numberof the two ace the hens GED posse of two rambers the sme ruber We fed he ramber by whch bah he wer enres bers are dsl We repeat the while oop tele get such armbar ite GcD doses fortwo aumbersthe veo reaches to 1, wth which every number s dvb anc thecontl ars ctf te wile 0m ow we check th vale of god i aul to 1 te iglay ech cout ext ee ply the calito vate of ese Progam 2321 + We © progam fed LOM of to tes. ‘orth step! + START. Sept PRINT Enter two number raram (Winiodeaio> Be, wena (Pine
id main) kK intl em; else) a ie a7 taal | Me ten=2 eletat=0 | atom emt , fi 4 gars en eels reat with the IRE UME his se he ps LM pose get unbe ‘ne Hep 09 TeMentRg the veo he ‘rel en unt we fi ht Both he eens (eves ae cus by thisaraeen Fray we pit the valu of thease, - nen ee Foe tai2 Vite a proyam fed SCO wetc a eninta. Pi oa cn eto spt + START. Supt PRNTEntr wo number sigh + INPUT, 2 Sug + nt
02 THEN kom = le vem=na Se 5 F (ok mad gd =O AND 82 mote "WEN GOTO step Sew: ged=gct=1, Sue: GoTo ep <0) Sou | fem nut» a nmol = chr Som yes THEN OAT EC Go we = a el d eat ‘ d shite i , pe Le 5 aeD0 n Toerowabon » ses econs_ hogan: Fda nett oer pera Pociecaa me Ktrogram 2324; Find ovo oe ning pour. (incon Vince roi > femme ori =0s
te: Ae te ree \) joer | fee ak || IE h a |e Stam neteeeetee eee eatissteos | mati ie | [27]iete we omarion [rot varios] encore anina|m ee oo noe |) Fusisos inessy sania o open #338 1 me 4 poown cose ven | enact Pe cu> ne |Winclude
Hwoid mani) ntl rene r intel set Pogan ee she c10n ddr 3 spams = (coat ae 7 | Ese ‘ot each| Independent. ofeach ee Sentaaes pereoeresanearmae Pe ee eee oc so oo LS Sa ac mtwnns * [sie | it To be al ae epee oe ene wate ovale oti ees ee i tr | ene oe nd [snes Se re ree ‘vole Condition i este and ue py LZ‘ea cn apear in bth ste dom. | A continue can sopar ony shi, do) ee ee ‘A brat uses the st or op stent | cntive doen wii ae terminate the moment i is ened, Loop secre ee 2 | 1 enw tr seen err tnstpevn ners | cmcitenennmeee When 2 break statement i encumeed | terminates th Bleck and ges the conta out ot the itch orfoop Ancudecstaah> (3) void main) | tndudecrcio n>) | vie mains ‘ Jc tte | ca: ert eve fete) | osm ‘ Ir 5) ites) orn ort, ) , output: Output: 1234 12346789 t weak 36 Weac regan gre canes a se 2 charges tai 10 085-25, : reaks ns Aeacharge=(oit-600 9 7 reas pas ) hanes in Chages = hag sss5 each) a 21 Wate a program to reverse te apts of» tive integer number for example fe ruber 8375 entre, the number byes shouts be 5738 22 Wie a program to dpiy ‘ema pope at nas aot ager 8 se nen pom a range st anerens nb mt nen oup woue eie biogrerming gay Dnt 1 (© sarang wl ec a ast (“Bo someting wi rat xed tat (own op tat ee 1.10 ete propram Ye ely ein pasten ting mate trae ‘ante program opi etning pata to nennepatve numbers Wetec program to check i the given smber of 2 ies an tee sach atthe ifthe cubes of is 1 egal the respecte, ao wom S| nso be mont nae" | oO" poawavcian MHI, ¢ ie , om See rm ae to yma ane te 2 te om Pro in Use out snare Siegen ana pnts the ds moe fo rar, put 1265 en es Some. ‘nema ni fori 01854) apia==0) wince, (ese 43-0) conte feo (50-0) itn End of Program | | sa td Salty Smt come retam Sy en 8 am on om ee ea : 27 eadme naman toning te 1 mame eentcin ma | em ess lcDelUCUL — — a at uaetesintenwtsmmneen| Toa maw — : eoeteet es cee ee “() Repeating a gen set of statements wanes ae ” econ eens os mn |" coe 6 The iterence between while and ouhile aime : statements te 1 eee ee ee Mercrceerccca|| 7 renee re , ee =| 40 Fina he cupput of me otowing program ° Q acy, om woman : | 151 eo 213 htatesencane ng {Coenen ene cnen —. \ oo. ie ec oa en tenant ermine \ Oe nseg | Ot Samar 2.11 etotlbin ueuttne en? a ‘Seesem men er : Semeneeen ise 2.45 he min ney Seeman ” rato) wan" pe een cy sen bree es ne teens ontecmaten ina 2.18 ne mmr ate a esmureep nomenon ies eee Amie) ot ‘oro vent or on ‘Sons enn srten vena) to ‘tome (Gromornnone sm Pacemeal int 928 pewomiroumeeumit te Co nes 7 Tm meine te a ore ore c > pi sei (Gomis ontacoen —— manano-t432n0-8 ne w (Guo are coe sat : fsas21004921.0843210 | qae me mmm nme # ae tatoo Ho at ito stn | O°" Sera mei open aor Verano” Soactancnon 0.12 Fc tutte tore omen os Old] 027 Tewtnne rmean ete teen oe ‘ 19 re meme ae {Sound on ne cndn 0 on 20 Semana acne | (Gavan sroe nat) | 38 fein ptt ig eam cole a © aa) 828 fete cna mig ren a t ran) taronso] roumcnge ‘ prise ee . Se $$ aey7 a ost ae d [90129456789 (Runtime ror (88 rind te opt of fllowng toga ecto ‘| vers eer ' as ina viet?) et 8 ) at or 9.36 Fedite cut of fowng ow we ws % (2) Comper fa) out ow te 1.32 Seetbacome seme ais v0: 2: o le —asio) 4 it i tosomtig ) ean 8 1 s04 wr9 (0) “Sosa ib nd tal nce (eno {None 1) “tore witb enced at at Biter | vi a4 ae ee et eal eee eave ote tere ” ie Se eee ore ae met ‘ manos ote tees ee boas uence , acne Vee same a os ‘ou 20 mean ° pag TEE ee aoe maar strat ics ee mene ace 1 * rem ren voulbeeinnsnemmest| oe mon wees a onsen ea Tiate: tol rent wastes | 63 Sean! 9.49 Freese —— qnmne ne eabooae — race avo etna te ee so wwe oon toe saan mtn or souce ene ee Goon etsom neste — en quan en oe tg a met ssegy nt oe? farzaesarse onan ae reese wee euseron se (aoune mip) 944 Feamenstnteng sso? > q.4t_ cose low Bt ttn me ran satrap stu =2? ; t = ce | oot bee | ea come : sens 3 rs : dota couc cutee ma we y ee ny ZL" ey MY EL igbat ae Fhoeye nese n608 ag pense orcas cyewmesaeoe meen oe) es tncopléw OW PoP=? acto t ow net cay ae troy ato ' ay mesg 0) yan en (8 Umea (Mosse AM) 47 Feast og peor (©) Mate we (2) None Nie tag net os peste leo py ‘rte smh ‘ en) ‘ pinto ase ae wot can pin nye bre 1 Ht fa Heo o q.as Tompes 8 stolons 25 tet. ug odorant wl oqared? layne (ey Slcve (eer (or) canbe ens (Nene store 1@:50 To porn one of he many cpeon sc, Tendon conden wich hd sera termes? | ate (saectve | (citer) ero) can be uses (anensatie soo @.51 Ine tate’ satamert ese" ptr © oe Helo o ay am me:0) (ove (Fase (6 Degas ene coon i (None ee stove (52. Tho can ba condion n ihe cae wre to steer tae Fae mcr ong sg sn, os per west ee (oom, oe imive arene te eg ean hg rene te POM Hs tat re on cynthia oe ane creation ameter 6 vou rary es" petra? oe poe vena q os see) exe ‘ me9 on vec , a)stmes (oes (57 “ea sori compu ae er at (oT race (0 Depenas onthe con oyttiees (ames dent) pes) (anon tn stove 0001 449 ne Du hc sen can on ea” thoes nen ror) 61 a canner wen ete te cr (9 ct mo et eer tb (ene pe strat oe (gtog of ne tine 88 tt metaeeteaer Ann) 2.82 ‘ormur ase ten ans be ls seen oe sone ee ster et eh be tn ne oa ote facan a a aoweantetean AM) 68 yer catet ess Pe ct (a wae fei ee eet ta bee a) rong feb ie torn neat (ott oe aera (a mmctoo sion amet ree cy warp | LWW My SEO" ndce) = meer gas rese’ ” ‘break: m = - alowed sete tS = | mance oe tee mcs te nf nd of program “mite ~ ea 7 9 rstace i , ' / os roman) Same ae i end of Program End of Progra et ar b=0.0=-2, id Progam , End of Program 2 ™ nore 1 generate o : Enc eon _ — oe tsetPan 2 pee 8 oor é EPpy o 4 ° , EnsctPrpar ‘ prereset ce : Endatpeaan Ender ogan : Feo a oe ae m Grows Endo * of az fico fmt |g ene (Nore, Scone ine ore (a Rintnn ey onmux ae qos rnsvecpase oes me toy vet ae 7 2 er manent qo me ee eet Ht wg a coe voit _—_ Ve Popa cae sunaton ef : . Smo <- tae = ve une eerste Wesaiectonta an os n= wag | | Soe emery ovens = a7 neh ner sue acomteromeg | Sec a hm Guise cnsioup ary @eeiwicwena | Samet 230) mane) mre t “and then continue the leoping process ? 8 =— ee a Soccaveas sre z we ieee Ome tn fa an wn ; , Cioomenerese Socal Soa ee an ae Grncecomes, amy | mwemaateeatia ua drone en oF ee @ ome cena ne i rare palate Sree : son) 7 ‘void maing) (Pagentiy (90 Marks) “ sia ‘ meer ra 66 Fite ouput ct he am ihe ve = “pai (ec) Meplaced bresk —(d) None of ese int e011 Nees, (s Marks) oe 4 peor . ° t 68 Find out the output ‘ tat a 7 sta oe sh 7 Soon : one sa bh : 1 re ae Pe ra see : Myson =. en 1 rommiaie orm rath tenet ucanstanéaSe ncaa me |einclude
\Gctude
r jes a canwes|| Sean Coreg rue | of een Seal it Som of neem names oer aa enn com me ae Sinan peal otras LTA |S wr wenn erons Rete eo | Se ae oon (Program 2.2.43) F ae ‘(20 Marks) = ©. WAP to print folowing satan bs = ye uct oe e : Tain o rr oe on WAP to print binary equiait Wires () Run ne or se © content Destine | remem 2248) . eae ‘mang | Compare te fotowrg © tte; an nop {0 brosk and contin net aa ame {Section 23.8) 2 _Wepmsenmteatinigecan | Hanna ene ‘Section 235) @rogeam 22:12) (10 marty Ye gereate 3 un wo maroer (Program 3242) a Mey2018 (Program 2234) (arto) (Proaram 224s)
You might also like
Control Structure-1 (202302IGS1232001)
PDF
No ratings yet
Control Structure-1 (202302IGS1232001)
38 pages
Looping / Iterative Statements: While Loop
PDF
No ratings yet
Looping / Iterative Statements: While Loop
7 pages
looping
PDF
No ratings yet
looping
44 pages
C Programming
PDF
No ratings yet
C Programming
22 pages
unit 3
PDF
No ratings yet
unit 3
58 pages
1.8 Flow Control - Loops (1)
PDF
No ratings yet
1.8 Flow Control - Loops (1)
10 pages
3.Loop Control Statements
PDF
No ratings yet
3.Loop Control Statements
8 pages
C Programming Part 8
PDF
No ratings yet
C Programming Part 8
10 pages
Pps ch4
PDF
No ratings yet
Pps ch4
40 pages
C Lab Worksheet 7 A C & C++ Repetition: The For Loop 1: For C & C++ Program Control 1 C/C++ Program
PDF
No ratings yet
C Lab Worksheet 7 A C & C++ Repetition: The For Loop 1: For C & C++ Program Control 1 C/C++ Program
6 pages
Looping: Prof. Nilesh Gambhava
PDF
No ratings yet
Looping: Prof. Nilesh Gambhava
42 pages
Iteration Constructs
PDF
No ratings yet
Iteration Constructs
23 pages
Lecture 8,9
PDF
No ratings yet
Lecture 8,9
60 pages
PPS Module-3 2
PDF
No ratings yet
PPS Module-3 2
95 pages
LM - Unit4 2
PDF
No ratings yet
LM - Unit4 2
8 pages
For Loop in C
PDF
No ratings yet
For Loop in C
38 pages
Lecture 5 Loops
PDF
No ratings yet
Lecture 5 Loops
51 pages
For Loop in C
PDF
No ratings yet
For Loop in C
38 pages
Lecture 7 Control
PDF
No ratings yet
Lecture 7 Control
59 pages
Unit 4 (C++) - Part Two
PDF
No ratings yet
Unit 4 (C++) - Part Two
54 pages
Represented By-Muhammad Faisal Imran Ruet, Cse09: Goto Statement
PDF
No ratings yet
Represented By-Muhammad Faisal Imran Ruet, Cse09: Goto Statement
16 pages
Unit 2 (a)
PDF
No ratings yet
Unit 2 (a)
48 pages
ALGELA1 2019 - Lecture 04 PDF
PDF
No ratings yet
ALGELA1 2019 - Lecture 04 PDF
54 pages
CSE 021 Lec07 Repetition Structure 14.12.21
PDF
No ratings yet
CSE 021 Lec07 Repetition Structure 14.12.21
35 pages
Lecture 3
PDF
No ratings yet
Lecture 3
34 pages
Lecture #3: Click To Edit Master Subtitle Style
PDF
No ratings yet
Lecture #3: Click To Edit Master Subtitle Style
30 pages
Lecture3 - Program Looping
PDF
No ratings yet
Lecture3 - Program Looping
34 pages
Loop Structures
PDF
No ratings yet
Loop Structures
25 pages
Programming and Data Structures: Control Flow: Looping
PDF
No ratings yet
Programming and Data Structures: Control Flow: Looping
55 pages
6_Loops in C
PDF
No ratings yet
6_Loops in C
33 pages
Unit 3 (Softcopy)
PDF
No ratings yet
Unit 3 (Softcopy)
32 pages
Loops in C Language
PDF
No ratings yet
Loops in C Language
13 pages
Basic Programming: Vietnam Academy of Science and Technology University of Science and Technology of Hanoi
PDF
No ratings yet
Basic Programming: Vietnam Academy of Science and Technology University of Science and Technology of Hanoi
49 pages
Topic 4 - Looping Statements Student
PDF
No ratings yet
Topic 4 - Looping Statements Student
19 pages
Chapter 3 Control Structures
PDF
No ratings yet
Chapter 3 Control Structures
36 pages
Loops in C Programming
PDF
No ratings yet
Loops in C Programming
40 pages
For (Initial Value Condition Incrementation or Decrementation) (Statements )
PDF
No ratings yet
For (Initial Value Condition Incrementation or Decrementation) (Statements )
7 pages
Lecture 4
PDF
No ratings yet
Lecture 4
30 pages
C Program Control: Objectives
PDF
No ratings yet
C Program Control: Objectives
23 pages
Decision Making & Looping
PDF
No ratings yet
Decision Making & Looping
20 pages
Looping Control Structures
PDF
No ratings yet
Looping Control Structures
29 pages
Looping
PDF
No ratings yet
Looping
8 pages
chapter2_4
PDF
No ratings yet
chapter2_4
42 pages
Lecture 5
PDF
No ratings yet
Lecture 5
18 pages
C Programming
PDF
No ratings yet
C Programming
41 pages
_Lect-06_Loops
PDF
No ratings yet
_Lect-06_Loops
32 pages
Loops: Pretest Loops Post Test Loops
PDF
No ratings yet
Loops: Pretest Loops Post Test Loops
33 pages
Brainware University: (ESCM201) Class Notes (Programming For Problem Solving)
PDF
No ratings yet
Brainware University: (ESCM201) Class Notes (Programming For Problem Solving)
7 pages
Lecture Looping and Machine Problem 3
PDF
No ratings yet
Lecture Looping and Machine Problem 3
5 pages
Chap4-Loop Statements
PDF
No ratings yet
Chap4-Loop Statements
40 pages
Lab Module Chapter6
PDF
No ratings yet
Lab Module Chapter6
14 pages
Chapter5 Repetition LoopStatements
PDF
No ratings yet
Chapter5 Repetition LoopStatements
39 pages
C Programming Notes
PDF
No ratings yet
C Programming Notes
8 pages
For Loop: - The Most Popular Looping Instruction - The For Loop Allows Us To Specify Three Things in A Single Line
PDF
No ratings yet
For Loop: - The Most Popular Looping Instruction - The For Loop Allows Us To Specify Three Things in A Single Line
17 pages
Program Control Strcutures
PDF
No ratings yet
Program Control Strcutures
32 pages
Lecture 2 - Iterative Control
PDF
No ratings yet
Lecture 2 - Iterative Control
13 pages
Experiment No-04 Program On Control Structure Loops
PDF
No ratings yet
Experiment No-04 Program On Control Structure Loops
7 pages
FCP L6 Looping
PDF
No ratings yet
FCP L6 Looping
42 pages
Labmanual Merged
PDF
No ratings yet
Labmanual Merged
47 pages