doubt in small factorials question

WHY THIS CODE ISNT WORKING

#include

using namespace std;

int main()
{
int t,x,i,fact[100],temp;
cout<<“input”;
cin>>t;
if(t>0&&t<=100)
{for(i=0;i<t;i++)
{temp=1;
cin>>x;
for(int k=1;k<=x;k++)
{
temp=temp*k;

  }
  fact[i]=temp;

}
cout<<“output”;
for(int j=0;j<t;j++)
{
cout<<"\n"<<fact[j];
}
}
return 0;
}

Hello,

Thanks for posting the question. It appears that you are new to Codechef so welcome to the community. I checked the code, and edited out some basic lines like -

i) There is no need for an “Input” prompt. The input will be given by the judging system and whatever you print our additionally will be marked as output. Since the output format is very strict, try and stick to that.

ii) No need to check if the test cases are within limits or not. The boundaries giving in the problem statement will always be valid. And it is the tester’s responsibility to ensure that the input is within limits.

I have submitted a valid code here after editing your code - CodeChef: Practical coding for everyone

iii) Test the code with the sample input. Once you are able to get the sample output, design your own sample cases that test boundary conditions. For example, try taking 100 factorial, or zero factorial.

In your case, the logic fails at anything more than 25, since the variable temp is an ‘int’ datatype which can hold at max data upto 2*10^9. So you need a different logic. As described here -

I hope that helps.

Warm Regards and all the best in your journey!

Ruddra

most of the question i encountered here needs to store large numbers…
so does we always have to apply this logic