ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int c = 0;
for (int i = 1; i <= 10; i++)
    for (int j = i; i * j <= 10; j++) c++;
printf("%d", c);
  1. A. 15
  2. B. 27
  3. C. 14
  4. D. 10

Correct answer: A. 15

c counts pairs i ≤ j with i·j ≤ 10. For i = 1, j runs 1 to 10 (10 pairs); for i = 2, j = 2 to 5 (4); for i = 3, only j = 3 (1); from i = 4, i·i already exceeds 10. Total 15. '27' counts ordered pairs.

More C Programming questions

Exams that ask this topic