Calculates n! = n × (n−1) × … × 1, where n is an integer of 0 or greater. By definition 0! is 1.
Explanation
The factorial n! is the product of every integer from 1 up to n.
n!=n×(n−1)×⋯×2×1 - n — an integer of 0 or greater
- n! — the resulting product
Factorials count arrangements. There are n ways to fill the first slot in a row, n−1 ways to fill the second from what is left, and so on down the line. Multiply those choices together and you get exactly n!, the number of ways to order n distinct objects.
Example
Take n=5.
5!=5×4×3×2×1=120 Equivalently, five objects can be lined up in 120 different orders.
Notes
- 0! is defined to be 1. There is precisely one way to arrange nothing at all, and the definition is also what keeps n!=n×(n−1)! working at n=1.
- n must be a whole number of 0 or greater. Negatives and fractions are rejected.
- Factorials explode. 10!=3628800, and 20! already runs to 19 digits.
- This calculator stops at n=170, because 171! overflows the range of double-precision arithmetic.
- For large n the result passes the point where every digit can be stored exactly, so read the display as an approximation.