What will be the output of the following C programming code: int i, j; for(i =…

2025

What will be the output of the following C programming code:
int i, j;
for(i = 1; i < 5; i += 2)
for(j = 1; j < i; j += 2)
printf("%d", j);

  1. A.

    1

  2. B.

    1 2

  3. C.

    1 3

  4. D.

    1 1 3

Attempted by 293 students.

Show answer & explanation

Correct answer: A

Answer: 1

Explanation:

  • The outer loop sets i = 1 and then i = 3 (it increments by 2 while i < 5).

  • When i = 1, the inner loop condition j < i is false (1 < 1 is false), so the inner loop body does not execute.

  • When i = 3, the inner loop starts with j = 1. Since 1 < 3 is true, it prints 1. Then j becomes 3, but 3 < 3 is false, so the inner loop stops and 3 is not printed.

  • No further iterations occur, so the program prints a single 1. Note that printf("%d") prints the digit with no added space or newline, so the exact output is: 1

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor