1.

Describe the output that will be generated by the following ‘C’ program.

Answer»

The output generated by given C program is: 

051530 

x=30

initially i=0<20, (i%5==0) is true so x=x+i=0+0=0, i is incremented to 2, again the next while loop, however condition (i%5==0) is false so i incremented and so on till i=5. 

At i=5, (i%5==0) is true so x=x+i=0+5=5, i is incremented to 6, again the next while loop, however condition (i%5==0) is false so i incremented and so on till i=10. 

At i=10, (i%5==0) is true so x=x+i=5+10=15, i is incremented to 11, again the next while loop, however condition (i%5==0) is false so i incremented and so on till i=15.

At i=15, (i%5==0) is true so x=x+i=15+15=30, i is incremented to 16, again the next while loop, however condition (i%5==0) is false so i incremented and out of while loop at i=20.

Outer block, it is printing the value of x which is 30.



Discussion

No Comment Found

Related InterviewSolutions