Files
Python/factorial.py

20 lines
382 B
Python
Raw Permalink Normal View History

def get_recursive_factorial(n):
if n < 0:
return -1
elif n < 2:
return 1
else:
return n * get_recursive_factorial(n-1)
def get_iterative_factorial(n):
if n < 0:
return -1
else:
fact = 1
for i in range(1, n+1):
fact *= i
return fact
2020-10-01 03:08:35 +05:30
print("input should be an integer")
print(get_recursive_factorial(6))
2020-10-01 03:08:35 +05:30
print(get_iterative_factorial(6))