N!

//题意及做法  大数阶乘

//*

  int 结果 = result[x] * 乘数 + 进位;

  每一位的计算结果有了,把这个结果的个位数拿出来放到这个数组元素上:

  result[x] = 结果%10;

  接下来的工作就是计算出进位:

  进位 = 结果 / 10;

*//

 1 #include<stdio.h>
 2 
 3 int main()
 4 
 5 {
 6 
 7 int n,i,j,k,temp;//temp表示结果
 8 
 9 int carry;//表示位数
10 
11 int a[40001];
12 
13 while(~scanf("%d",&n))
14 
15 {
16 
17 a[0]=1;
18 
19 int dight=1;
20 
21 for(i=2;i<=n;i++)
22 
23 {
24 
25 for(carry=0,j=1;j<=dight;j++)
26 
27 {
28 
29 temp=a[j-1]*i+carry;
30 
31 a[j-1]=temp%10;
32 
33 carry=temp/10;
34 
35 }
36 
37 while(carry)
38 
39 {
40 
41 dight++;
42 
43 a[dight-1]=carry%10;
44 
45 carry/=10;
46 
47 }
48 
49 }
50 
51 for(int k=dight;k>=1;k--)
52 
53 printf("%d",a[k-1]);
54 
55 printf("
");
56 
57 }
58 
59 return 0;
60 
61 }
View Code
原文地址:https://www.cnblogs.com/awsent/p/4266917.html