Skip to main content

Factorial

Definition​

The Factorial Algorithm is a mathematical procedure used to calculate the factorial of a non-negative integer

Practice​

factorial(n):
if n is negative:
throw "Invalid input: Cannot compute factorial of a negative number"
else if n equals 0 or 1:
return 1
else:
return n * factorial(n - 1)