ProgrammingHard

int s = 0; for (int i = 0, j = 5; i < j; i++, j--) s += i * j; printf("%d", s); What is printed?

  1. A. 9
  2. B. 15
  3. C. 12
  4. D. 10

Correct answer: D. 10

The pairs are (0,5), (1,4) and (2,3), contributing 0 + 4 + 6 = 10. Then i = 3 and j = 2 end the loop.

More C Programming questions

Exams that ask this topic