The
{{factorial}} mathematical function template returns
, the
factorial of
, for
nonnegative integers in
, otherwise returns an error message. (For
, the returned value would not be an exact integer but only an approximation with a floating point number representation.) This template works by repeating conditional multiplications.
Usage
- {{factorial|nonnegative integer}}
or
- {{n!|nonnegative integer}}
Valid argument
Returns
for a
nonnegative integer in
(worse than most calculators, which go up to
, although only as an approximation with a floating point number representation), otherwise returns an error message.
Examples
Examples with valid argument
Code
|
Result
|
|
Code
|
Result
|
{{factorial|0}} |
1 |
|
{{n!|0}} |
1
|
{{factorial|1}} |
1 |
|
{{n!|2}} |
2
|
{{factorial|2}} |
2 |
|
{{n!|2}} |
2
|
{{n!|3}} |
6 |
|
{{n!|4}} |
24
|
{{n!|5}} |
120 |
|
{{n!|6}} |
720
|
{{n!|7}} |
5040 |
|
{{n!|8}} |
40320
|
{{n!|9}} |
362880 |
|
{{n!|10}} |
3628800
|
{{n!|11}} |
39916800 |
|
{{n!|12}} |
479001600
|
{{n!|13}} |
6227020800 |
|
{{n!|14}} |
87178291200
|
{{n!|15}} |
1307674368000 |
|
{{n!|16}} |
20922789888000
|
Examples with invalid argument (returns an error message)
Code
|
Result
|
{{n!|17}} |
Factorial error: Argument must be a nonnegative integer up to 16
|
{{n!|80}} |
Factorial error: Argument must be a nonnegative integer up to 16
|
{{n!|-1}} |
Factorial error: Argument must be a nonnegative integer up to 16
|
{{n!|0.5}} |
Factorial error: Argument must be an integer
|
{{n!|text}} |
Factorial error: Argument must be an integer
|
{{n!|6 blobs}} |
Factorial error: Argument must be an integer
|
Code
Cf. {{Factorial/test#Code}}.
Test
Cf. {{Factorial/test}}.
See also