small factorials ! wrong answer but it is working just the right way in my system

#include<stdio.h>
#include<string.h>
#include
#include
using namespace std;
long double fact(int);
int main()
{
int t,n,i=0;

long double sol[100];
scanf("%d",&t);
while(i<t)
{
scanf("%d",&n);
sol[i]=fact(n);
++i;
}
cout<<endl;
for(i=0;i<t;i++)
cout<<setprecision(160)<<sol[i]<<endl;

return 0;

}
long double fact(int f)
{
if(f==0)
return 1;
else
return f*fact(f-1);
}

Test your code for n=100. The answer should have 24 zeros at the end and a lot more other digits.You answer will have only 10-15 digits as that is the maximum range of long double.

No C or C++ variable is sufficient for this. you will need to use arrays. Here is an awesome tutorial by @kuruma for your help.

1 Like

thank you !!!
!!