Given a number N, the task is to calculate factorial of N.
In mathematics, the factorial of a positive integer N is the product of all positive integers less than or equal to N. The recursive formula to calculate factorial of a given positive integer N is
N! = N * ( N -1 )! N! = 1 if N = 1 or N = 0
Input : N = 3 Output : 6 Input : N = 5 Output : 120
Method 1 : Iterative Way
In this method, we will use a loop to iterate over the sequence of numbers to get the factorial.
Below is the implementation of above approach
Method 2 : Use of Recursion
In this method, Recursive formula N! = N * (N -1) ! is used to calculate the factorial of the given number.
Below is the implementation of above approach.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.