ProgrammingModerateAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer n = 10, s = 0
for (i = 1 to n)
    if (n mod i == 0)
        s = s + i
    end if
end for
Print s
  1. A. 8
  2. B. 17
  3. C. 55
  4. D. 18

Correct answer: D. 18

Divisors of 10 are 1, 2, 5, 10 → 18. Excluding n itself (proper divisors) gives 8; a perfect number would have proper-divisor sum equal to n.

More Pseudocode and Code Tracing questions

Exams that ask this topic