Showing posts with label factorial of a number. Show all posts
Showing posts with label factorial of a number. Show all posts

07 January 2012

factorial of number in console applications

int count = 1;
Console.Write("Enter Number for factorial: ");
int number = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= number; i++)
{
count = count * i;
}
Console.Write(count);
Console.Read();

or
public static long numfact(long n)
{
if (n <= 1)
return 1;
else
return n * numfact(n - 1);
}
Console.Write(numfact(5));