Factorial
Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n.
For example factorial of 6 is
6*5*4*3*2*1 which is 720.
Recursive Solution: Factorial can be calculated using following recursive formula.
Factorial of 5 is 120
Iterative Solution: Factorial can also be calculated iteratively as recursion can be costly for large numbers. Here we have shown the iterative approach using both for and while loop.
Using For loop
Output :
One line Solution :
Output:
Last updated