Factorial using iterative method and Recursive method

 

Recursive Method

def Recursive(n):
if n==1:
return 1
else:
return n*Recursive(n-1)

n=int(input("Enter a number "))
print(Recursive(n))

Iterative Method

def iterative(n):
fac=1
for i in range(n):
fac=fac*(i+1)
return fac

Comments

Popular posts from this blog

React Installation with Vite and Tailwind css (Steps to Installation)

Insert Data In mongoDb

Class methods as an alternative Constructor