Code:
int x = 10;
while(x > 0)
{
printf(“%d “, x);
x -= 3;
}
Answer: The loop starts with x = 10
. In each iteration, the value of x
is decremented by 3. The loop will print the value of x
before it is decremented. The loop will continue as long as x > 0
.
- First iteration:
x = 10
(prints 10, thenx
becomes 7) - Second iteration:
x = 7
(prints 7, thenx
becomes 4) - Third iteration:
x = 4
(prints 4, thenx
becomes 1) - Fourth iteration:
x = 1
(prints 1, thenx
becomes -2)
The loop terminates when x
becomes less than or equal to 0. So the output will be:
Output: 10 7 4 1