Factorial (n!)

The factorial of n is denoted by n! and calculated by the product of integer numbers from 1 to n.

For n>0,

n! = 1×2×3×4×…×n

For n=0,

0! = 1

Factorial definition formula

n!=\begin{Bmatrix}1 & ,n=0 \\ \prod_{k=1}^{n}k & ,n>0\end{matrix}” align=”absmiddle”></p>
<p>For examples:</p>
<p><span style=1! = 1
2! = 1×2 = 2
3! = 1×2×3 = 6
4! = 1×2×3×4 = 24
5! = 1×2×3×4×5 = 120
6! = 1×2×3×4×5×6 = 720
7! = 1×2×3×4×5×6×7 = 5040

Recursive factorial formula

n! = n×(n-1)!

Advertisements

For example:

7! = 7×(7-1)! = 7×6! = 7×720 = 5040

Striling’s approximation

n!\approx \sqrt{2\pi n}\cdot n^n\cdot e^{-n}

For example:

7! ≈ √2π7 ⋅ 77⋅e-7 = 5040

Factorial table

C program for factorial calculation

double factorial(unsigned int n)

{

     double fact=1.0;

     if( n > 1 )

          for(unsigned int k=2; k<=n; k++)

               fact = fact*k;

     return fact;

}

Advertisements