【大数乘法】

 1 #include<cstdio>
 2 #include<cstring>
 3 const int Len = 100;
 4 void Mul(char a[],char b[],char c[])//大数乘法
 5 {
 6     int i,j;
 7     int alen = strlen(a),blen = strlen(b);
 8     memset(c,0,Len);
 9     for(i = 0; i < alen; i++)
10         for(j = 0; j < blen; j++) //处理进位
11         {
12             c[i + j] += a[i] * b[j];
13             if(c[i + j] >= 10)
14             {
15                 c[i+j+1] += c[i+j] / 10;
16                 c[i+j] %= 10;
17             }
18         }
19 }
20 int Print (char n[])
21 {
22     int i;
23     for(i = Len-1; i > 0; i--)
24         if(n[i] != 0) break;
25     for(; i >= 0; i--)
26     //将0排除
27         printf("%d",n[i]);
28     printf("
");
29     return 0;
30 }
31 int Input (char n[])//将大数读入的函数
32 {
33     char s[Len];
34     int i,l;
35     for(i = 0; i < Len; i++) n[i] = 0;
36     if(scanf("%s",s) < 1) return -1;
37     l = strlen(s);
38     for(i=0; i<l; i++) //将输入的大数逆置
39         n[i] = s[l-i-1]-'0';
40     return 0;
41 }
42 int main(){
43     char a[Len],b[Len],c[Len];
44     Input(a);
45     Input(b);
46     Mul(a,b,c);
47     Print(c);
48     return 0;
49 }
原文地址:https://www.cnblogs.com/zhengbin/p/4436053.html