ProgrammingHardCAT · MBA placement

The number of ordered pairs (x, y) of positive integers with x y = 36 is counted by the procedure below. What is printed?

The number of ordered pairs (x, y) of positive integers with x * y = 36 is counted by the procedure below. What is printed?
count = 0
for x = 1 to 36
    if 36 mod x == 0 then count = count + 1
end for
Print count
  1. A. 8
  2. B. 3
  3. C. 10
  4. D. 9

Correct answer: D. 9

The ordered pairs correspond to the 9 divisors of 36, one pair per divisor. Leaving out x = 36 loses a pair, counting only one half of the pairs gives a different count, and the range starting at zero adds a pair that is not positive.

More Pseudocode and Code Tracing questions

Exams that ask this topic