ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int c = 0;
for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
        if (j == i) continue;
        if (j > i + 1) break;
        c++;
    }
}
printf("%d", c);
  1. A. 15
  2. B. 14
  3. C. 10
  4. D. 20

Correct answer: B. 14

For each i, j counts 0 … i + 1 except j = i, capped at 4. That is 1, 2, 3, 4 for i = 0 to 3, and 4 for i = 4 (j = 0 to 3; j = 5 is never reached). Total 14. '15' forgets the cap at the last row.

More C Programming questions

Exams that ask this topic