In this video, we will see a JavaScript program to find the Factorial of a Number. Basically, the Factorial of a non-negative integer is the 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.
Factorial of 5 is 5*4*3*2*1 which is 120.
Here we see two different method for calculate factorial of any integer number.
1. Recursive Solution:
Factorial can be calculated using following recursive formula. n! = n * (n-1)!
n! = 1 if n = 0 or n = 1
2. Iterative Solution:
Factorial can also be calculated iteratively as recursion can be costly for large numbers. Here we have see the iterative approach using both for and while loop for finding factorial.
Program to Find Factorial: https://www.geeksforgeeks.org/program-for-factorial-of-a-number/