0

Hi all,

I have written a simple function to compute factorial in C++.

It computes OK until 31! which is 738197504. Now for factorial 32 it gives me a negative result and for 34 it gives me 0.

I know that on my machine LONG_MAX is 2147483647.

So in my recursive algorithm when I try to compute 32! it would cross the max value. That is OK but then I should get an error message and not an incorrect value.

Here comes the code

```
"
const long factorial(const long n)
{
long fn = 1;
if (n>1) fn = (n*factorial(n-1));
return fn;
"
```

ANY IDEA???

*Edited 3 Years Ago by mike_2000_17*: Fixed formatting