Recursive Factorial method. : Function Definition « Language Basics « C# / C Sharp






Recursive Factorial method.

 


using System;

public class FactorialTest
{
   public static void Main( string[] args )
   {
      for ( long counter = 0; counter <= 10; counter++ )
         Console.WriteLine( "{0}! = {1}", counter, Factorial( counter ) );
   } 
   public static long Factorial( long number )
   {
      if ( number <= 1 )
         return 1;
      else
         return number * Factorial( number - 1 );
   } 
} 


              








Related examples in the same category

1.Recursive sum methodRecursive sum method
2.Use a recursive method, travel, to journey from start to finishUse a recursive method, travel, to journey from start to finish
3.Recursive function in actionRecursive function in action
4.Define functionDefine function
5.Catch StackOverflowException for recursive function