#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;
}
#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;
}
Try the following input, and consider why the output is wrong from the third value (13) onwards.
6
11
12
13
14
20
40
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.