ProgrammingHardCAT · MBA placement

The procedure below sums the decimal digits of 2^10 = 1024 once and prints the result. What is printed?

The procedure below sums the decimal digits of 2^10 = 1024 once and prints the result. What is printed?
x = 2^10; total = 0
while x > 0: total = total + x mod 10; x = x div 10
Print total
  1. A. 4
  2. B. 8
  3. C. 7
  4. D. 0

Correct answer: C. 7

The digits 1, 0, 2 and 4 sum to 7. Counting the digits gives 4, the digit sum of 512 gives 8, and the product of the digits is 0 because one digit is zero.

More Pseudocode and Code Tracing questions

Exams that ask this topic