ProgrammingModerateTCS NQT · Accenture pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer c = 0
for (each d from 1 to 36)
    if (36 mod d == 0)
        c = c + 1
    end if
end for
Print c
  1. A. 6
  2. B. 9
  3. C. 8
  4. D. 7

Correct answer: B. 9

This counts the divisors of 36 = 2² × 3², which is (2 + 1)(2 + 1) = 9: 1, 2, 3, 4, 6, 9, 12, 18, 36. A perfect square has an odd number of divisors.

More Pseudocode and Code Tracing questions

Exams that ask this topic