Suppose that the input is 0 0 8 12 50 7 13 -1. What is the output of the following C++ code?
Suppose that the input is 0 0 8 12 50 7 13 -1. What is the output of the following C++ code?


Befor while loop,
Variable sum will take 1st input so, sum = 0.
Variable count will take 2nd input so, count = 0.
Variable num will take 3rd input so, num = 8.
inside while loop :
1st iteration : sum = 0 + 8 = 8 , count = 1, num = 4th input ( 12 ) .
2nd iteration : sum = 8 + 12 = 20 , count = 2, num = 5th input ( 50 ) .
3rd iteration : sum = 20 + 50 = 70 , count = 3, num = 6th input ( 7 ) .
4th iteration : sum = 70 + 7 = 77 , count = 4, num = 7th input ( 13 ) .
5th iteration : sum = 77 + 13 = 90 , count = 5, num = 8th input ( -1 ) .
Now, as, count becomes 5 which is greater than 4. so, loop will break.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps









