Calculating the factorial of a number is a basic excercise while learning to program in C, many of us have done it iteratively, it can also be done recursively. I am posting both iterative and recursive versions below.

Everything looks good and nice but what's if you want to calculate " 1000! " or the factorial of greater values ? :) The " unsigned int " type can memorize a value between 0 and +4,294,967,295 but " 1000! " is more much greater than the dimension of " long double " which is the greatest data type in C/C++. I think this is a good question. :) I'm waiting suggestions and ideas.

shabbir

7Dec2007 09:07

Re: Calculating Factorial (Recursively & Iteratively)

The greatest has also the limitation for large numbers and I think you are with the greatest "long double"

pr1nc3k1d

7Dec2007 14:28

Re: Calculating Factorial (Recursively & Iteratively)

Yes, it has, but i'm thinking on an algorithm which not calculates the result,but it generates it into a vector or a list. For example you can get a number with more than 1000 digits as result But if I put every digit of the number into a list I could view it and print it on the screen or into a file. So I think it could be a possible solution for this problem because there is no other data types which could memorize such a number. Opinions ?

pr1nc3k1d

8Dec2007 05:45

Re: Calculating Factorial (Recursively & Iteratively)

I made it but I don't really like it cuz` it's slow. It took about 6-7 minutes waiting for the result of " 1000! ".