Factorial in C#
Example for versions
Microsoft Visual C# 2008,
gmcs 2.0.1
This example uses recursive factorial definition.
using System;
class Program
{
static long Factorial(int n)
{
if (n == 0)
return 1;
else
return n * Factorial(n - 1);
}
static void Main(string[] args)
{
for (int i = 0; i < 17; i++)
Console.WriteLine("{0}! = {1}",i,Factorial(i));
}
}
Comments
]]>blog comments powered by Disqus
]]>