How can find the factorial of 100! in c#.

Posted by Bageshkumarbagi under C# on 10/10/2012 | Points: 10 | Views : 4500 | Status : [Member] | Replies : 3
hi,
I want to find the factorial of 100!. I am finding the problem which type of data type i take. 100! has very large value.

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied



Responses

Posted by: Pgayath on: 10/12/2012 [Member] Starter | Points: 25

Up
0
Down
You can try with double

static double Factorial(double number)
{
double Result;
try
{
if (number <= 1)
Result= 1;
else
Result= number * Factorial(number - 1);

return Result;
}
catch (Exception e)
{
return 0;
}
finally
{

}
}

static int Main(string[] args)
{
Console.WriteLine("The factorial of 100 is: {0}\n",
Factorial(100));
Console.ReadLine();
return 0;
}

Copy the value and paste it in the excel and format the cell to Number. You can see the result.

Thanks and Regards,
Gayathri P


Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bageshkumarbagi on: 10/12/2012 [Member] Starter | Points: 25

Up
0
Down
Hi , Gayathri Purushothaman

factorial of 100 is a big number .we cannot store it in double.

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: K011gusain89 on: 10/29/2012 [Member] Starter | Points: 25

Up
0
Down
static void Main(string[] args)
{
int n, i;
double f;
Console.WriteLine("Enter an integer: ");
n = Convert.ToInt32(Console.ReadLine());
f = n < 0 ? 0 : 1;
for (i = n; i >= 1; i--)
f *= i;
Console.WriteLine("Factorial = " + f);
Console.ReadLine();
}

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response