The following is my implementation of the SPOJ problem: http://www.spoj.com/problems/FCTRL2/
#include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int carry=0,k,i,j,num,arr[1000]={1};
scanf("%d",&num);
for(i=1;i<=num;i++)
{
for(j=0;j<=k;j++)
{
arr[j]=arr[j]*i+carry;
carry=arr[j]/10;
arr[j]=arr[j]%10;
}
while(carry)
{
k++;
arr[k]=carry%10;
carry/=10;
}
}
for(i=k;i>=0;i--)//doubt
{
printf("%d",arr[i]);
}
printf("\n");
}
return 0;
}
I guess there is a mistake in displaying array in reverse direction, but when I change the condition i.e for(i=0;i<=k;i++) it prints the array. Please help me solve this problem.