Math, asked by sonstriker4p39o84, 1 year ago

int sum = 0;
int x = 0
do {
x++;
sum += x;
if (sum < 5)
x++;
}
while (x < 5) ;

The answer pls ?

A-9
B-13
C-7
D-11
E-4

Answers

Answered by iritu121
0
I think the answer is none of thes

sonstriker4p39o84: really ?
sonstriker4p39o84: oh :(
Answered by SandipanDey
0
The variables sum and x are preinitialized to 0.
In the first pass of the do-while loop,
x = 0 + 1 = 1
sum = 0 + x = 0 + 1 = 1
The variable sum if less than 5.
Hence, x will be incremented by 1. Now, x = 2
Condition check : Yes, x < 5.
Second pass,
x = 1 + 1 = 2
sum = 1 + 2 = 3
sum < 5
Hence x will be incremented by 1. Now, x = 3
Condition check : Yes, x < 5
Third pass,
x = 2 + 1 = 3
sum = 3 + 3 = 6
sum not less than 5.
No increment in x value.
Condition check : Yes, x < 5
Fourth pass,
x = 3 + 1 = 4
sum = 6 + 4 = 10
sum not less than 5. If part skipped.
Condition check : Yes, x < 5
Fifth pass,
x = 4 + 1 = 5
sum = 10 + 5 = 15
If part skipped.
Condition not satisfied, loop terminates.

So the answer will be 15.
All the option in your question fails to match.
Similar questions