2017-12-05 20:18:03 -08:00
|
|
|
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")
|
2017-12-05 20:18:03 -08:00
|
|
|
print(get_recursive_factorial(6))
|
2020-10-01 03:08:35 +05:30
|
|
|
print(get_iterative_factorial(6))
|