Codechef - Small Factorial

Problem Link

Problem Description : 

Problem Name : 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

Solution : 


/// Codechef
/// problem name : Small Factorial (Basically its pretty Big!!)
/// Author : Md. shohanur Rahaman
/// problem type: math
#include<stdio.h>
#include<string.h>
#define N 250
#define B 10
int main()
{
int fact[N],i,j,n,t,size=0,carry=0,tmp=0,a;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
memset(fact,0,N);
fact[0]=1;
size=1;
carry=0;
for(j=1;j<=n;j++){
for(i=0;i<size;i++){
tmp=fact[i]*j+carry;
fact[i]=tmp%B;
carry=tmp/B;
}
while(carry>0){
fact[size++]=carry%B;
carry=carry/B;
}
}
for(a=size-1;a>=0;a--){
printf("%d",fact[a]);
}
printf("\n");
}
return 0;
}