problem in submitting answer for small factorials

/my code for small factorial progtam/

#include<stdio.h>
double FACT(int n) ;
int main()
{
int X,i=0;
int NUM[100];
scanf("%d",&X);
if((1<=X)&&(X<=100)){
while(i<X){
scanf("%d",&NUM[i]);
i++;
}

}
else return 0;
i=0;
while(i<X){
        if((1<=NUM[i])&&(NUM[i]<=100)){
printf("%.0lf\n",FACT(NUM[i]));
}
else return 0;
i++;
}
return 0;
}

double FACT(int n){
int i;
double sum=1;
for(i=1;i<=n;i++){
sum*=i;
}
return(sum);
}

/* i tried many times but every time it says WRONG ANSWER. What's the problem in this code now, Please help */

I used your code to calculate 100! Here is the output. Compare it with the correct answer here. Obviously, your answer is wrong. It is because of the precision issues of double. The range of values stored in a double is much higher. But, the result will be correct only in the higher order digits.

You need to use, what are known as “big integers” for this problem.

Please read the tutorial on how to solve this problem here.

why are you asking the same question again

1 Like

thanks @michal27, closing…