杭电acm1042

 

N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 40154    Accepted Submission(s): 11153


Problem Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
 

 

Input
One N in one line, process to the end of file.
 

 

Output
For each N, output N! in one line.
 

 

Sample Input
1 2 3
 

 

Sample Output
1 2 6

 

 

           #include<stdio.h>
 int main()
 {
   long n,m,i,j,b;      long a[10000];(不能太大,也不能太小)
   while(scanf("%ld",&n)!=EOF)
   {
      a[0]=1;m=1;
      for(i=1;i<=n;i++)
      {
         b=0;
         for(j=0;j<m;j++)
         {
           a[j]=a[j]*i+b;         
           b=a[j]/10000;*****
           a[j]=a[j]%10000;
         }
         if(b>0){a[m]=b;m++;}******
      }
       printf("%ld",a[m-1]);******
      for(i=m-2;i>=0;i--)
      {
        printf("%4.4ld",a[i]);*******
      }
      printf("\n");
   }
 }

posted @ 2013-03-29 21:09  《 》  阅读(189)  评论(0编辑  收藏  举报