Factorial calculator using python
Hey
guys once again welcome to the Decoders blog, I hope you all are doing
well and today I'm present with factorial calculator(using iterative and recursive methods both)which
you can create using python, The given code will help you to built it, so
just follow the codes and make your factorial calculations easily , and enjoy it while solving maths
#factorial_recursive method
def factorial_recursive_method(n):
if n==0:
return 1
else:
return n*factorial_recursive_method(n-1)
n=int(input("Enter the number: \n"))
print("Using recursive method:",factorial_recursive_method(n))
#factorial_iterative_method
def factorial_iterative_method(n):
fac=1
for i in range(n):
fac= fac*(i+1)
return fac
n=int(input("Enter the number: \n"))
print("Using iterative method:",factorial_iterative_method(n))
Comments
Post a Comment