Programming Pandit

c/c++/c#/Javav/Python


Latest Update

Tuesday, November 17, 2020

Python program to calculate the factorial of an integer using recursion by G Krishna Chauhan

 

Source Code


def factorial(n): 

    if n == 1: 

        return n 

    else: return n*factorial(n-1) 

   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 ", factorial(num))



OUTPUT


enter the number: 5

The factorial of  5  is  120

 

No comments:

Post a Comment