阶乘的精确值

 1 #include <stdio.h>
 2 int max = 3000;
 3 int f[3000];
 4 int main()
 5 {
 6     int i,j,n;
 7     scanf("%d",&n);
 8     f[0] = 1;
 9     for(i = 2;i <= n;i++)
10     {
11         int c = 0;
12         for(j = 0;j < max;j++)
13         {
14             int s = f[j]*i + c;
15             f[j] = s % 10;
16             c = s/10;
17         }
18     }
19     
20     for(j = max-1;j >= 0;j--)
21     {
22         if(f[j])
23             break;
24     }
25     
26     for(i = j;i >= 0;i--)
27     {
28         printf("%d",f[i]);
29     }
30     return 0;
31 }

示例:

30
265252859812191058636308480000000

posted on 2015-12-02 22:49  LeoSanford  阅读(202)  评论(0编辑  收藏  举报

levels of contents