5.2 高精度运算 六月飞雪

5.2.1   小学生算术    http://poj.grids.cn/practice/2562/

View Code
 1 # include <stdio.h>
 2 
 3 int main () {
 4 
 5     int a, b;
 6     while (scanf("%d %d", &a, &b) == 2) {
 7         if (!a && !b) break;
 8         int c = 0, ans = 0;
 9         for (int i = 9; i>=0; i--) {
10             c = (a%10 + b%10 + c) >9 ? 1 : 0;
11             ans += c;
12             a /= 10; b /= 10;
13         }
14         if (!ans) printf("No ");
15         else printf("%d ", ans);
16         printf("carry operation");
17         if (ans>1) putchar('s');
18         printf(".\n");
19     }
20 
21     return 0;
22 }

5.2.2  阶乘的精确值  (未找到原题网址)

View Code
 1 # include <stdio.h>
 2 # include <string.h>
 3 
 4 const int maxn = 2600;
 5 int a[2600];
 6 
 7 int main () {
 8 
 9     int n;
10     while (scanf("%d", &n) != EOF) {
11         memset(a, 0, sizeof(a));
12         a[0] = 1;
13         int i;
14         for (i = 2; i <= n; ++i) {
15             int c = 0, s;
16             for (int j = 0; j < maxn; ++j) {
17                 s = a[j]*i+c;
18                 a[j] = s % 10;
19                 c = s / 10;
20             }
21         }
22         for (i = maxn-1; i >= 0; --i)
23             if (a[i]) break;
24         for (; i >= 0; i--)
25             printf("%d", a[i]);
26         puts("");
27     }
28 
29     return 0;
30 }
原文地址:https://www.cnblogs.com/lanhj/p/2853500.html