All mock tests are FREE till 31 December — register to save your progress

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);

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: A. 1

Explanation

The outer loop runs for i = 1 and i = 3. For i = 1 the inner condition j < 1 is false immediately. For i = 3, j = 1 prints 1, then j becomes 3 and 3 < 3 is false. Output: 1.

More Programming Languages and Computer Graphics questions