![]() |
C# Example: Factorial 1 |
This program calculates the factorial of an integer: using System;
public class Program
{
static long Factorial(long number)
{
long p = 1;
if (number > 1)
for (long i = 2; i <= number; i++)
p *= i;
return p;
}
static int Main(string[] args)
{
Console.WriteLine("The factorial of 5 is: {0}\n", Factorial(5));
return 0;
}
}
This would produce: The factorial of 5 is: 120 Press any key to continue . . .
|
|
|
||
| Home | Copyright © 2007 FunctionX, Inc. | |
|
|
||