Question:

What will be the output of the following program?

#include <stdio.h>
int main() {
 int i, j;
  for (i = 0, j = 5; i < j; i++, j--) {
    printf("%d %d |", i, j);
  }
  return 0;
}

Show Hint

i rises from 0, j falls from 5; loop ends the moment i is no longer less than j.
Updated On: Jul 2, 2026
  • 0 5 | 1 4 | 2 3 | 3 2 | 4 1 |
  • 0 5 | 1 4 | 2 3 | 3 2 |
  • 0 5 | 1 4 | 2 3 |
  • Compilation error
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: Read the loop setup. i starts at 0 and j starts at 5. Each pass increases i by 1 and decreases j by 1. The loop runs while i < j.

Step 2: First pass. i is 0, j is 5, and 0 < 5 is true, so it prints 0 5 |. Then i becomes 1 and j becomes 4.

Step 3: Second pass. i is 1, j is 4, and 1 < 4 is true, so it prints 1 4 |. Then i becomes 2 and j becomes 3.

Step 4: Third pass. i is 2, j is 3, and 2 < 3 is true, so it prints 2 3 |. Then i becomes 3 and j becomes 2.

Step 5: Fourth check. i is 3, j is 2, and 3 < 2 is false, so the loop stops. The full output is 0 5 | 1 4 | 2 3 |. The answer is option C.
Was this answer helpful?
0
0