ProgrammingModerate

The sum of the digits of n = 10^9 - 1 is computed with a loop that divides by 10 each time. How many loop iterations run?

  1. A. 9
  2. B. 10
  3. C. 8
  4. D. 1000000000

Correct answer: A. 9

Each n /= 10 removes one decimal digit, and 10^9 - 1 = 999999999 has nine digits, so the loop runs nine times. 10 counts the digits of 10^9 itself, and 1000000000 confuses the value with its digit count.

More C Programming questions

Exams that ask this topic