This site is supported by donations to The OEIS Foundation.

Template:Factorial

From OeisWiki
(Redirected from Template:N!)
Jump to: navigation, search
The {{factorial}} mathematical function template returns 
n!
, the factorial of 
n
, for nonnegative integers
n
in 
[0..16]
, otherwise returns an error message. (For 
n   ≥   17
, 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 
n!
for a nonnegative integer
n
in 
[0..16]
(worse than most calculators, which go up to 
69!
, 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