Sort by

recency

|

1146 Discussions

|

  • + 0 comments

    run code was successful.But hidden test cases are failure.why?? anyboidy please explain to my problem

  • + 0 comments

    My solution with JavaScript:

    // Base case at 2 to avoid redundancy: multiplying by 1 does not change the result.
    function factorial(n) {
        if(n > 2) {
            return n * factorial(n-1);
        } else {
            return 2;
        }
    }
    
  • + 0 comments

    Java 15

    I tried to use BigInteger instead of int, and I got an error because BigInteger doesn't overflow. I checked the constraints, which allow numbers between two and twelve. If someone uses twelve with int in this exercise, an overflow will occur. It would be better to explain this in the exercise or reduce the constraints to eleven.

  • + 0 comments

    return (math.factorial(n))

  • + 0 comments
    C# 
    
    
    class Result
    {
    //i change this method to void and ref result instead of return as
    //there is an issue with ascii bla3
    
        public static void factorial(int n, ref int result)
        {
            for (Int32 i = n; i > 0; i--)
            {
                result *= i;
            }
        }
    }
    
    class Solution
    {
        public static void Main(string[] args)
        {
            Int32 n = Convert.ToInt32(Console.ReadLine());
    
            Int32 result = 1;
            
            Result.factorial(n,ref result);
    
            Console.WriteLine(result);
        }
    }