138 Programming and Data Structures
OUTPUT:
Enter two numbers : 8 4
Multiplication of 8 * 4 : 32
Explanation Here also the two numbers are entered through the keyboard. The infinite fo r loop
is used and counter %c ' is initialized to 1 and 'd' to 0. Variable 'd ' is used for storing the result
after repetitive addition. After adding value of 'a ' in 'd ' each time the counter %c ' is tested with
' b ' . If there is no match, counter is increased and the program goes back in the loop. Again the
addition is performed. When 1 c ' equals to 'b ' (repetitive addition of the first number till the counter is
equal to second number), program terminates using goto statement and result of multiplication is
displayed.
6.23 Calculate sum & average of five subjects.
# in clu d e < s td io .h >
# in clu d e <conio.h >
mainO
{
in t a ,b ,c,d ,e,su m B 0 ,i;
flo a t avg;
c l r s c r ();
printf ("nEnter The Marks o f Five Subjects");
fo r (i=l;i<=5;i++)
printf ("
[%d] Student: ",i);
if (scanf ("%d %d %d %d %d"/&a,&b,&xf&d/&e)==5)
{
sum=a+b+c+d+e;
avg=sum/5;
printf ("n Total Marks o f Student[%d] %d",i,sum);
printf ("n Average Marks o f Student[%d] %f
",i,avg);
I
else
I
clrscrO;
printf ("n Type Mismatch");
)
I
OUTPUT:
Enter The Marks of Five Subjects