Python Program to find Factorial of a Large Number
Factorial of a Large Number
On this page we will learn how to find the Factorial of a Large Number in python.
Factorial of a number is product of all the positive numbers less then and equals to the number we are finding factorial. On this page we will see two different ways to solve the Question one by inbuilt function and another by creating a function.
- Input : 5
- Output : 120
- Explanation : 5! = 5 x 4 x 3 x 2 x 1 = 120
Method 1 : Without Inbuilt Function
- Pass the value of n to a function
- Initialize a variable name answer with value one
- Run a while loop until value of n is greater then 1
- Multiply the value of n with ans and assign the result in ans
- Decrement value of n by one
- Return the value of answer
ans = 1
while n > 1: ans *= n n -= 1
n = 5 print(factorial(n))
Method 2 : Using Inbuilt Function for Factorial
- From math library import Factorial Function
- Assign to value to n for which you want to find Factorial
- Pass the value of n to factorial function and assign the result to ans
- Print ans
from math import factorial n = 5 ans = factorial(n) print(ans)
If you want to practice similar Questions click on given button.