Decision Statements 97
printf ("Total :% d Average : % .2f', sum,avg);
if (a<35 I I b<35 I I c<35 I I d<35 I I e<35)
I
printf ("nResult: Fail ");
exit();
I
if(avg>34 && avg<50)
printf ("n Result: Third Division");
else
if(avg>49 && avg <60)
printf C'n Result: Second Division");
else
if(avg>60 && avg<75)
printf ("n Result: First division");
else
if(avg>75 && avg <100)
printf ("nResult : Distinction");
getcheO;
I
QUTE.UT :
Enter Marks
P C B M E H
75 75 75 75 75 75
Total : 450
Average: 75.00
Result: Distinction
Explanation In the above program marks of six subjects are entered through the keyboard. Their
sum and averages are calculated. First i f statement checks the condition whether the marks in
individual subjects are less than 35. If so, message displayed will be "Result: Fail" and the program
terminates. The logical OR ( | | ) is used here.
The average marks obtained are checked with different conditions. The i f e l s e blocks are
used. Based on the conditions the statements are executed.
5.5 THEbreakSTATEMENT
The keyword b reak allows the programmers to terminate the loop. The Break skips from the loop
or block in which it is defined. The control then automatically goes to the first statement after the
loop or block. The B reak can be associated with all conditional statements.
We can also use break statements in the nested loops. If we use break statement in the innermost
loop then the control of the program is terminated only from the innermost loop.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.181.57