Factorial calculation by Iterative and Recursive methods
def factorial_iterative(num):
fac = 1
for i in range(num):
fac = fac*(i+1)
return fac
def factorial_recursive(num):
if num==0 or num==1:
return 1
else:
return num * factorial_recursive(num-1)
num = int(input("Input your number: "))
print(factorial_iterative(num))
print(factorial_recursive(num))
Comments
Post a Comment
Write something to CodeWithAbdur!