Data Structures & AlgorithmsModerateTCS NQT · number puzzle

Problem: How many decimal digits does 100! have? Run the code.

Problem: How many decimal digits does 100! have? Run the code.
import math
print(len(str(math.factorial(100))))
What is printed?
  1. A. 100
  2. B. 156
  3. C. 160
  4. D. 158

Correct answer: D. 158

100! is about 9.33 * 10^157, which has 158 digits. The estimate from Stirling's formula lands near the same value, which is the sanity check.

More Coding Interview Problems questions

Exams that ask this topic