Factorial Program Algorithm Analysis

randerson112358
2 min readSep 13, 2017

The Factorial Algorithm is great for recursion

What is factorial ?

In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example
5! = 5 x 4 x 3 x 2 x 1 = 120. It is just the product of an integer and all the integers below it.-Wikepedia

How to write a factorial function using recursion ?

The factorial program can be written recursively, because it is a function that calls itself.

Pseudo Code
1. func factorial(n)
2. if (n == 1)
3. return 1
4. return n *
factorial(n -1)

C-Program

factorial(int n)
{
//Base Case
if(n == 1)
return 1;

return n *factorial(n-1);
}

You can see how to convert a function to recurrence relation in this video, it’s not the factorial function, but a…

--

--

No responses yet