easy off the top of my head. realize that factorial is a summation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
float factorial( float n )
{
float x = n;
float s = n - 1;
for( ; s > 0 && x > 0; x -- )
{
s *= x;
}
return s != 0 ? s : 1;//!0 = 1 (special case)
}
probrably shouldn't have coded it for this forum if it was homework.
edit: correct me if I'm wrong, but factorial is only valid for whole numbers.
double edit: the factorial of such a large number would take forever and would be impossible on some computers for such a large number.
Not insane, it's an assignment with a sufficiently large factorial to ensure that the bignum class used is flexible enough to cope. Remember factorials get big really quickly. And DeXecipher, please don't post solutions to homework.
For the record, 450000! takes up less than 960 KiB of memory (not counting the space to calculate it). Far from impossible to compute, even on the smallest of modern computers. In fact, a while back there was a thread where we tried various methods to compute even larger factorials, up to one million.
Nothing is impossible :-) If a C++ library is able to compute the determinat, inverse of a matrix ( and apply linear algebra on matrices) being large than 1000000X1000000 dimension.. it is possible, you need to try and try and try till you find a way...
@ JAI SINGH
Sorry I cant give you the class, you need to try it yourself, learn by doing by trying, not by coping... once you have your solution than we may provide you other options/solutions
what I meant is that the average sized data type cannot store it, which goes back to the Big Integer problem. Its too big for your average (int) and would cause an overflow error.