Computer Science, asked by BendingReality, 10 months ago

b. Write a program in python lang. to find the factorial of a number recursive function

Answers

Answered by Kshitij1537
0

Answer:

Python Program to Find the Factorial of a Number Using Recursion

Take a number from the user and store it in a variable.

Pass the number as an argument to a recursive factorial function.

Define the base condition as the number to be lesser than or equal to 1 and return 1 if it is.

Otherwise call the function recursively with the number minus 1 multiplied by the number itself.

Explanation:

pls mark as brainliest

Answered by rajdas23218
5

Answer:

def recur_factorial(n):

if n == 1:

return n

else:

return n*recur_factorial(n-1)

# take input from the user

num = int(input("Enter a number: "))

# check is the number is negative

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:

Similar questions