Factorial Program using recursion in Python

   

         Factorial Program using recursion in Python

Factorial of n is the product of all positive descending integers. Factorial of n is denoted by n!. For example:

  1. 5! = 5*4*3*2*1 = 120  
  2. 3! = 3*2*1 = 6  


Program:

def factorial(n): 
  if (n == 0): 
    return 1;  
  else : 
    return(n * factorial(n-1))
  
   
if __name__ == "__main__":
    fact=0
    number=int(input("Enter a number: "))
    fact = factorial(number);  
    print("Factorial of" ,number," is", fact)






No comments:

Post a Comment