Recursive Factorial Calculation

  • Share this:

Code introduction


Calculate the factorial of a given non-negative integer. The factorial is denoted as n!, which represents the product of all positive integers up to n.


Technology Stack : Recursion

Code Type : Recursive function

Code Difficulty : Intermediate


                
                    
def factorial(n, acc=1):
    if n == 0:
        return acc
    else:
        return factorial(n-1, n*acc)                
              
Tags: