Answer on Question #54847 – Programming – C
Condition
What is the output of this program? Please explain the logic for the output.
int main()
{
int x = 4, y = 0;
while (x >= 0)
{
x--;
y++;
if (x == y)
continue;
else
printf("\n %d %d", x, y);
}
return 0;
}Solution
You declare variable x with value 4 and variable y with value 0. Later you have loop, which will work until x is more than 0 and x is equal 0. In every loop iteration variable x is decrementing (it means x − 1) and variable y is incrementing (it means y + 1). Later you have condition – if variable x is equal variable y in this loop iteration, program will go to the next loop iteration immediately. If variable x on this loop iteration doesn't equal variable y, program will print variables x and y. In the second loop iteration variable x is equal 2 and variable y is equal 2, but you will not see this in output, because in this moment your program will work with "if" operator.
Answer
Output:
3 1
1 3
0 4
-1 5
http://www.AssignmentExpert.com/