my code:
codechef gives me wrong anwer
problem_code: (FCTRL2)
for(int j = 0;j<T;j++)
{
cin>>n;
if((n==1) || (n==0))
{
ans = 1;
}
else
{
for(int i = 1; i <=n; ++i)
{
ans = ans * i;
}
}
a[j] = ans;
}
my code:
codechef gives me wrong anwer
problem_code: (FCTRL2)
for(int j = 0;j<T;j++)
{
cin>>n;
if((n==1) || (n==0))
{
ans = 1;
}
else
{
for(int i = 1; i <=n; ++i)
{
ans = ans * i;
}
}
a[j] = ans;
}
See the range in that problem. Seen? Yes it is 1 to 100. The max factorial calculation done with above logic is 21(even not 22) because no datatype can store such a large value generated after computations so u must consider solving it with array or use Bigint lib in c++.