Ad

The factorial of a positive integer n, denoted by n!, is the product of all positive integers less then or equal than to n:

n! = n(n-1)(n-2)...(2)(1)

5! = (5)(4)(3)(2)(1) = 120

By convenction, 0! equals to 1.

https://en.wikipedia.org/wiki/Factorial

Code
Diff
  • using System;
    
        public static class RecursiveFactorials
        {
            public static int Kata(long n)
            {
                int i = 1;
                if (n != 0)
                {
                    while (n / i != 1)
                    {
                        n /= i;
                        i++;
                    }
                } else
                {
                    n = i;
                }
                return (int) n;
            }
        }
    • def factorial(n):
    • # your code goes here
    • return
    • using System;
    • public static class RecursiveFactorials
    • {
    • public static int Kata(long n)
    • {
    • int i = 1;
    • if (n != 0)
    • {
    • while (n / i != 1)
    • {
    • n /= i;
    • i++;
    • }
    • } else
    • {
    • n = i;
    • }
    • return (int) n;
    • }
    • }