Can anyone check dha code pls , i am getting crt ans but it shows wrong solution

#include
using namespace std;
int main()
{
int n,i,t;
cin>>t;
while(t–)
{
int fact=1;
cin>>n;
if(n<=100)
{
for(i=1;i<=n;i++)
{
fact=fact*i;

    }
cout<<fact<<endl;
 }

}
return 0;

}

1 Like

Try the following input, and consider why the output is wrong from the third value (13) onwards.

6
11
12
13
14
20
40
2 Likes

I thing the problem is in while statement try this while(-t)

//code

#include
using namespace std;
int main()
{
int n,i,t;
cin>>t;
while(-t)
{
int fact=1;
cin>>n;
if(n<=100)
{
for(i=1;i<=n;i++)
{
fact=fact*i;

}

cout<<fact<<endl;
}
}
return 0;

}

It is giving wrong answer bcoz of the int overflow.

1 Like