Recursive function in action : Function Definition : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Function Definition »

 

Recursive function in action









    


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

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Function Definition