#include<stdio.h>
#include<string.h>
#define Max 505
int main()
{
char A[Max], B[Max], temp[Max];
int a[Max] = {0}, b[Max] = {0}, s[Max * 2] = {0};
int len_a, len_b, i, j;
scanf("%s %s", A, B);
if(strlen(A) < strlen(B))
{
strcpy(temp, A);
strcpy(A, B);
strcpy(B, temp);
}
len_a = strlen(A);
len_b = strlen(B);
for(i = 0; i < len_a; i++)
a[i] = A[len_a - i - 1] - '0';
for(i = 0; i < len_b; i++)
b[i] = B[len_b - i - 1] - '0';
for(i = 0; i < len_b; i++)
for(j = 0; j < len_a; j++)
s[i + j] += a[j] * b[i];
for(i = 0; i < 2 * len_a; i++)
if(s[i] >= 10)
{
s[i + 1] += s[i] / 10;
s[i] %= 10;
}
i = 2 * len_a;
while(s[i] == 0)
i--;
if(i < 0)
printf("0");
else
{
for(;i>= 0; i--)
printf("%d",s[i]);
}
return 0;
}
高精度运算之乘法
最新推荐文章于 2024-07-30 16:21:09 发布