Small Factorials
You are asked to calculate factorials of some small positive integers.
Input
An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.
Output
For each integer n given at input, display a line with the value of n!
Example
Sample Input
4 1 2 5 3
Sample Output
1 2 120 6
C++ Code
#include<iostream>
using namespace std;
int main()
{
int t,n,fact[200],i,j,k,c,temp,x;
cin>>t;
for(i=0;i<t;i++)
{
cin>>n;
c=n;
j=0;
while(c>0)
{
fact[j]=c%10;
c=c/10;
j++;
}
while(n>1)
{
n--;
temp=0;
for(k=0;k<j;k++)
{
x=fact[k]*n+temp;
fact[k]=(x%10);
temp=x/10;
if(k==j-1)
{
while(temp>0)
{
fact[j]=temp%10;
temp=temp/10;
j++;
}
break;
}
}
}
for(k=j-1;k>=0;k--)
cout<<fact[k];
if(k)
cout<<"\n";
}
return 0;
}