# overflow problem

This is a discussion on overflow problem within the C Programming forums, part of the General Programming Boards category; Code: int main() { int i,j=1,n; printf("donnez n\n"); for(i=0;i<n;i++) { j*=(n-i); } printf("%i!=%i",n,j); return 0; } [quote] my program has ...

1. ## overflow problem

Code:
```int main()
{
int i,j=1,n;
printf("donnez n\n");
for(i=0;i<n;i++)

{

j*=(n-i);

}

printf("%i!=%i",n,j);

return 0;
}```
[quote]
my program has a problem with integers (< =13)

i need help !!!
i want a function that calcul factoriel(n) with n >>]0,+00[
Code:
`--------- no recursion function please---------------`
[\quote ]

2. Code:
```int i,j=1,n;
printf("donnez n\n");
for(i=0;i<n;i++)```
Your n needs some sort of value.

If you want to calculate the factorial of j,
set j as the number you want to factorial.
and the n = j-1.

Code:
```int i, j,n;

j = 5; n = j-1;

for (i=n; i>0; i--)
j*=i;```
Ryan

3. Code:
```sorry about missing
scanf("%i",&n);```
the problem percist with n==13
....!!!

4. Originally Posted by enjoy
Code:
```sorry about missing
scanf("%i",&n);```
the problem percist with n==13
....!!!

13 Factorial is greater than 2 to the power 32.

Can't be represented as a 32-bit integer.

Regards,

Dave

5. ..... !!!!

6. If your compiler supports it, try using long long variables.

Generally, if you need to work with huge numbers you need to have a bignum library like GMP from www.gnu.org

7. Originally Posted by jim mcnamara
If your compiler supports it, try using long long variables.

Generally, if you need to work with huge numbers you need to have a bignum library like GMP from www.gnu.org

64-bit ints will take you all the way to 20 factorial.

Regards,

Dave