Calculate Factorial with recursive method - CSharp Data Structure Algorithm

CSharp examples for Data Structure Algorithm:Factorial

Description

Calculate Factorial with recursive method

Demo Code

using System;//w ww  .  j a  v a 2  s .  c o  m
class MyMath
{
   public static long Factorial (long number)
   {
      if (number == 0)
         return 1;
      else
         return (number * Factorial (number - 1));
   }
}
class TestFactorial
{
      public static void Main()
      {
         Console.WriteLine("4 factorial is {0}", MyMath.Factorial(4));
      }
}

Result


Related Tutorials