Is there a way to find sum of digits of 100?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Taken literally, the sum of the digits of 100 is just 1. In practice, though, this question usually means "how do I find the sum of the digits of 100!," the classic large-number problem where direct mental arithmetic stops being realistic and you need either big integers or manual digit-array arithmetic.
The Answer Depends on the Exact Question
There are two different interpretations:
- sum of digits of
100is1 + 0 + 0 = 1 - sum of digits of
100!is648
The tags on this article point to the factorial version, so the rest of the explanation focuses on 100!.
Compute 100! With Arbitrary-Precision Integers
The straightforward approach is:
- calculate
100! - convert it to decimal digits
- sum those digits
In Python this is very simple because integers already grow to arbitrary size.
The final printed sum is 648.
Why This Works So Well in Python
Python hides the hard part for you. Its integer type automatically allocates more space as the number grows, so 100! is just another integer expression, not a special case.
That is why converting to a string is a practical solution here. Once the number exists exactly, each character in the decimal string is one digit, and summing them is trivial.
For a one-off problem, this is better than inventing a custom number representation.
Languages Without Built-In Big Integers
In languages where ordinary integer types overflow, you need either a big-integer library or a digit-array approach.
A simple manual method stores the large number as decimal digits and performs multiplication one digit at a time. The outline looks like this:
This version is still Python, but it demonstrates the algorithm rather than relying on math.factorial. The list stores the number in reverse digit order, which makes carry handling easy.
Understanding the Trailing Zeros
People often notice that 100! ends with many zeros and wonder if that changes the method. It does not. Trailing zeros contribute 0 to the digit sum, so they are harmless.
They appear because factorials contain many factors of 10, and each factor of 10 comes from pairing a factor 2 with a factor 5. Since 100! contains plenty of both, decimal zeros accumulate at the end.
That affects the shape of the number but not the basic algorithm for summing its digits.
Avoid Overflow in Fixed-Width Types
One reason beginners get stuck is trying to compute 100! in a 32-bit or 64-bit integer type.
For example, even 21! is already too large for an unsigned 64-bit integer. So this approach fails:
The lesson is that the real problem is not digit summation. It is representing 100! exactly in the first place.
If You Only Need the Known Result
If this is a math puzzle rather than a programming task, the important numeric result is simply:
But in programming interviews or exercises, the interesting part is usually showing a reliable method, not just quoting the answer.
Common Pitfalls
- Confusing
100with100!, which are very different questions. - Using fixed-width integers and overflowing before the calculation finishes.
- Computing the factorial correctly but forgetting to convert each digit character back to a number before summing.
- Treating trailing zeros as a separate special case when they already contribute zero naturally.
- Writing a complicated custom big-number implementation when the language already has big integers.
Summary
- The sum of the digits of
100is1, but the sum of the digits of100!is648. - The easiest solution is to compute
100!, convert it to a string, and sum the digits. - Python makes this easy because its integers are arbitrary precision.
- In fixed-width languages, use a big-integer library or manual digit-array multiplication.
- The real challenge is representing
100!exactly, not adding the digits once you have it.

