ProgrammingModerate

A program sums the digits of 10^5 numbers with one loop per number that divides by 10. What is the total cost, about?

  1. A. About 10^10 divisions, too slow
  2. B. About 10^5 divisions, which is fast enough
  3. C. About 10^12 divisions, too slow
  4. D. About 10^6 divisions, which is fast enough

Correct answer: D. About 10^6 divisions, which is fast enough

Each number has at most 10 digits, so the work per number is about 10 steps, and 10^5 numbers take about 10^6 divisions.

More C Programming questions

Exams that ask this topic