Sort by

recency

|

1152 Discussions

|

  • + 0 comments

    c#

    public static int factorial(int n)

    {

                return n>1?n*factorial(n-1):1;
    

    }

  • + 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);
        }