Write a Python Program to Find Factorial of Number Using Recursion.

Write a Python Program to Find Factorial of Number Using Recursion.

Factorial Number

The factorial of a non-negative integer ( n ) is the product of all positive integers less than or equal to ( n ). It is denoted by ( n! ) and is defined as:
𝑛! = 𝑛×(𝑛−1)×(𝑛−2)×…×3×2×1
For example:
5! = 5×4×3×2×1 = 120
0!is defined to be 1.

Factorials are commonly used in mathematics, especially in combinatorics and probability, to count the number of ways a set of elements can be arranged or selected.

Program
def recur_factorial(n):
    if(n<=1):
        return n
    else:
        return n*recur_factorial(n-1)
    
if __name__=="__main__":
    num=int(input("Enter the number: "))
    if(num<0):
        print("Sorry, factorial does not exist for negative numbers")
    elif(num==0):
        print("The factorial of 0 is 1")
    else:
        print("The factorial of",num,"is",recur_factorial(num))
        



Output:

Enter the number: 5
The factorial of 5 is 120

Enter the number: 6
The factorial of 6 is 720



More Questions


80 . Write a Python Program to Find Factorial of Number Using Recursion.
81 . Write a Python Program to calculate your Body Mass Index.
82 . Write a Python Program to calculate the natural logarithm of any number.
83 . Write a Python Program for cube sum of first n natural numbers?
84 . Write a Python Program to find sum of array.



For latest job updates join Telegram Channel: https://t.me/sateeshm