As stated in the question, the factorial of non-negative integer
n is written n! and is defined as -
n! = n * (n – 1) * (n – 2) . . . 1 (for values of n greater
than or equal to 1) and n! = 1 (for n = 0).
For example, consider n = 5, the n! = (5*4*3*2*1) = 120.
The following algorithm illustrates the computation of factorial of a non-negative integer 'n' -
START
Step 1: Read 'n'
Step 2: If n < 0 then let f = 0 else let f = 1
Step 3: Let i = n
Step 4: Repeat Step 4 to Step 6 for i >= 1
Step 5: f = f * i
Step 6: i = i - 1
Step 7: Print Factorial :- 'f'
STOP