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