Sort by

recency

|

1151 Discussions

|

  • + 0 comments

    Python :

    def factorial(n):
        return 1 if n<=1 else n*factorial(n-1)
    
  • + 0 comments

    code in python 3

    def factorial(n):
        if n == 0:
            f_ct = 1
            return f_ct
        else:
            f_ct = n*factorial(n-1)
            return f_ct
    
  • + 1 comment

    See a lot of solutions using logic, isn't the simplest (in JS)

    function factorial(n) {
        // Write your code here
        var f = 1
        for (let i = 1; i <= n; i++){
            f *= i 
        }
        return f
    }
    
  • + 0 comments

    C#

                if(n == 1) return n;
        else
        {
            return n *= factorial(--n);
        }
    
  • + 0 comments
    def factorial(n):
        # Write your code here
        if n==0 or n==1:
            return 1
        else:
            return n*factorial(n-1)