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

Popular posts from this blog

Quotation marks to wrap an element in HTML

What is the difference between iostream and iostream.h in cpp?

The Basic Structure of a Full-Stack Web App