Skip to content

Commit 6da3627

Browse files
authored
Python Program
Python Program to Find Factorial of Number Using Recursion
1 parent 99cf7d7 commit 6da3627

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Factorial of a number using recursion
2+
3+
def recur_factorial(n):
4+
if n == 1:
5+
return n
6+
else:
7+
return n*recur_factorial(n-1)
8+
9+
num = 7
10+
11+
# check if the number is negative
12+
if num < 0:
13+
print("Sorry, factorial does not exist for negative numbers")
14+
elif num == 0:
15+
print("The factorial of 0 is 1")
16+
else:
17+
print("The factorial of", num, "is", recur_factorial(num))

0 commit comments

Comments
 (0)