HDU 1042 N!(大数阶乘)

                  N!



 

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
 
代码:
 1 #include<cstdio>

 2 using namespace std;

 3 

 4 int main()

 5 {

 6     int i,n,digit,temp,carry,j;

 7     int a[40005];

 8     while(scanf("%d",&n)!=EOF)

 9     {

10         a[0]=1;

11         digit=0;

12         for(i=2;i<=n;i++)

13         {

14             for(carry=0,j=0;j<=digit;j++)

15             {

16                 temp=a[j]*i+carry;

17                 a[j]=temp%10;

18                 carry=temp/10;

19             }

20             while(carry)

21             {

22                 a[++digit]=carry%10;

23                 carry/=10;

24             }

25         }

26         for(i=digit;i>=0;i--)

27         printf("%d",a[i]);

28         printf("\n");

29     }

30     return 0;

31 } 

 

你可能感兴趣的:(HDU)