Thursday, 8 May 2014

SPOJ Problem Set (classical) 24. Small factorials Problem code: FCTRL2

//http://www.spoj.com/problems/FCTRL2/
//Program to find factorial of small numbers
//mayur shingote :)
#include<stdio.h>
#include<string.h>
int main()
{
   int t,n,z,a[200],m,i,x,temp;
   scanf("%d",&t);
   while(t>0)
   {  scanf("%d",&n);
      a[0]=1;m=1;i=1;
      while(i<=n)
      {  temp=0;z=0;
         for(;z<m;z++)
         { x=a[z]*i+temp;
           a[z]=x%10;
           temp=x/10;
         }
         while(temp!=0)
         {  a[z++]=temp%10;
            temp/=10;
            m++;
         }
         i++;
      }
      for(i=--m;i>=0;i--)
      printf("%d",a[i]);
      t--;
      printf("\n");
   }
   return 0;
}

No comments:

Post a Comment