1. ## Expanding Factorial Limits

Code:
```#include <stdio.h>
#include <conio.h>
int main(){
int ts;
int carpim;
printf("Enter Integer : ");
scanf("%d",&ts);
carpim=1;
while(1<ts){
carpim=carpim*ts;
ts=ts-1;
}
printf("Factorial = %d 'dir",carpim);
getch();
return 0;
}```
in the code you see everything is clear. but when i try to calculate 18 factorial is give output as " -898433024 " . what must i do help me

2. One thing you can do is to use an unsigned. However that won't get rid of the problem. you could use a double and that could store more numbers accuractly. But the real problem comes in that 18! is really big. And if you kept going higher and higher you'll eventually get to a point that a double can't store it accuratly. So you'll have to start looking into a big int library

3. You could also consider finding out the memory limit of your doubles and if your factorial calculation is reaching the highest value, it can output that number and do the rest in another calculation and output that.

Think of a calculator that gets overloaded on digits. It will output as many digits as it can then give an e to a certain power to express the rest. You could do something similar. It might take a bit of thinking to make it work, but it's just a suggestion.

4. it seems my problem is big to solve. if someone can eidt the code and make i will be happy.

5. When calculating very large factorials you might want to use Stirling's approximation (which is much faster), http://en.wikipedia.org/wiki/Stirling%27s_approximation . To do 5! you would do:
n = sqrt((2 * M_PI) * 5) * pow((5 / 2.718281828459), 5); This is useful because big int libraries are normally a fair bit slower than normal ints and so that is normally a better method. It is however, only an approximation of the factorial.

6. Originally Posted by SNaRe
it seems my problem is big to solve. if someone can eidt the code and make i will be happy.
That's a very bold statement to make. Considering you have no idea how difficult this actually could be, you're asking some stranger to do your work for free because you can't handle it?