ProgrammingVery hard

int c = 0; for (int i = 1; i <= 10; i++) for (int j = i; j <= 10; j += i) c++; printf("%d", c); What is printed?

  1. A. 55
  2. B. 10
  3. C. 27
  4. D. 100

Correct answer: C. 27

For each i the inner loop runs floor(10 / i) times: 10 + 5 + 3 + 2 + 2 + 1 + 1 + 1 + 1 + 1 = 27. This is the O(n log n) sieve pattern.

More C Programming questions

Exams that ask this topic