Small integer factorial


#1

#include
using namespace std;
int fact(int x)
{
int f=1;
for(int i=1;i<=x;i++)
{
f=f*i;
}
return f;
}

int main()
{
int t,n,i,facto;
cin>>t;
for(i=0;i<t;i++)
{
cin>>n;
facto=fact(n);
cout<<facto<<"
";
}
return 0;
}
now what is wrong??


#2

Here you had unwanted equal signs
and one more thing use long instead of int because the number can be large but I don’t think so that even long long can hold the factorial of 100, you might need different approach

#include

using namespace std;

int fact(int x)

{

int f=1;

for(int i=1;i<=x;i++)

{

f=f*i;

}

return f;

}

int main()

{
int t,n,i,facto;

cin>>t;

for(i=0;i<t;i++)
{
cin>>n;

facto=fact(n);

cout<<facto<<"
";

}

return 0;

}