这是我看过的最简单的算法,思路就是我们小学学过的乘法运算。
void
Multiple(
char
A[],
char
B[],
char
C[])
... {
int LenA = strlen(A), LenB = strlen(B);
int Index = LenA + LenB - 1;
// B is the multiplicand
for (int i = LenB - 1; i >= 0; i--, Index--)
...{
if (B[i] != '0')
...{
// Decide which is the current digit
int Sum = 0, In = 0, k = Index;
for (int j = LenA - 1; j >= 0; j--, k--)
...{
// Calculate the current digit
Sum = (A[j] - '0') * (B[i] - '0') + (C[k] - '0') + In;
// Get the current digit
C[k] = Sum % 10 + '0';
// Get the in value
In = Sum / 10;
}
// The last in value
C[k] = In + '0';
}
}
}
... {
int LenA = strlen(A), LenB = strlen(B);
int Index = LenA + LenB - 1;
// B is the multiplicand
for (int i = LenB - 1; i >= 0; i--, Index--)
...{
if (B[i] != '0')
...{
// Decide which is the current digit
int Sum = 0, In = 0, k = Index;
for (int j = LenA - 1; j >= 0; j--, k--)
...{
// Calculate the current digit
Sum = (A[j] - '0') * (B[i] - '0') + (C[k] - '0') + In;
// Get the current digit
C[k] = Sum % 10 + '0';
// Get the in value
In = Sum / 10;
}
// The last in value
C[k] = In + '0';
}
}
}