Data Structures & AlgorithmsHardWipro · Accenture pattern

What does this code print?

What does this code print?
int c = 0, n = 10;
for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
        for (int k = j + 1; k < n; k++)
            c++;
printf("%d", c);
  1. A. 720
  2. B. 1000
  3. C. 165
  4. D. 120

Correct answer: D. 120

Each increment matches one choice of indices i < j < k from 0..9, so c = C(10, 3) = 120. 165 = C(11, 3) is an off-by-one; 720 counts ordered triples (10 × 9 × 8).

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic