ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains

The procedure below counts the digits of 2^10 by repeated division by 10. What is printed?

The procedure below counts the digits of 2^10 by repeated division by 10. What is printed?
N = 2^10; d = 0
while N > 0
    N = N div 10; d = d + 1
end while
Print d
  1. A. 3
  2. B. 4
  3. C. 5
  4. D. 11

Correct answer: B. 4

1024 has four digits, and the loop runs once for each digit until the value reaches 0. Subtracting one from the digit count gives 3, taking half of 10 gives 5, and counting the binary digits of 1024 gives 11.

More Pseudocode and Code Tracing questions

Exams that ask this topic