Output the factorial of 100

I have used the function below but the output is always 0. Is there any way to output the factorial of 100?
1
2
3
4
5
6
unsigned long long factorial(unsigned long long n)
{
    if(n==0)
        return 1;
        return n*factorial(n-1);
}
I have used the function below but the output is always 0.

No it's not. What values did you pass the function?

Is there any way to output the factorial of 100?

Probably not with this function because a 64 bit integer is too small to be able to hold the value of 100!.
You have some options:
- Use a big integer library that supports c++ or make your own
- Use a different programming language - java, python, perl, etc
- solve it mathematically by using properties of log

http://ideone.com/5AJMf7
Last edited on
So how can I make my own a big integer library?
The way that I am doing it for the one I'm making at the moment is simply to store an array of numbers, and perform operations against the arrays. For example, for addition, you would start from the lowest values, add them together, if they exceed the 'maximum' value for each block you subtract the 'maximum' value and add that number divided by the 'maximum' value to the one in front.

However, its probably much easier to use one already made for you. If you don't have it already, I'd highly recommend the multiprecision libraries available with boost, see http://www.boost.org/ (and for documentation on there multiprecision libraries, see http://www.boost.org/doc/libs/1_55_0/libs/multiprecision/doc/html/index.html ).
Last edited on
Use arrays
http://stackoverflow.com/a/269289

Also if you look around on the internet, there are free implementations you can download
But how many digits can:
• a unsigned long long int have?
• a long double (I don't know how to describe it) have before and after the point?
And what is the maximum number of them?
Last edited on
how many digits can a unsigned long long int have?
 
std::numeric_limits<long long int>::digits10


how many digits can a long double have before and after the point

The precision depends on how large the number is.
Topic archived. No new replies allowed.