Implement a function of a computational large bit number (such as more than 100 digits) multiplied results (please completely use algorithm)
#include
#include
#include
Multiply (char * a_strmultp1, char * a_STRMULTP2)
{
INT LEN1; // the length of multiplier1
INT LEN2; // the length of multiplier2
LEN1 = Strlen (a_strmultp1);
Len2 = Strlen (a_strmultp2);
Char * strret = new char (iMULTP1LEN IMULTP2LEN); // the result;
MEMSET (Strret, '0', Imultp1len Imultp21);
// if Either's length is 0, the meaning;
IF (len1 <= 0 || LEN 2 <= 0)
{
COUT << "error" << endl;
exit (0);
}
INT I;
Int J;
IC Icarry; // the carry;
Int idigit; // the Digit;
Icarry = 0;
iDigit = 0;
Int Len;
INT TEMP = 0;
For (i = len2-1; i> = 0; i -)
{
For (j = len1-1; j> = 0; J -)
{INT JJ = LEN2 LEN1-J-I-2;
IDIGIT = (A_StrMultp2 [i] - '0') * (a_strmultp1 [j] - '0') iCarry;
Icarry = iDigit / 10;
iDigit = iDigit% 10;
Temp = Strret [JJ] - '0' iDigit;
IF (TEMP / 10)
Icarry = Icarry TEMP / 10;
Strret [JJ] = TEMP% 10 '0';
Icarry
Strret [JJ 1] = ICARRY% 10 Strret [JJ 1];
Icarry = Icarry / 10;
}
}
Icarry
{
Strret [len2 len1-1] = iCarry '0';
Len = len2 len1-1;
}
Else
Len = len2 len1-2;
For (i = le; i> = 0; i -)
Cout << Strret [I];
Cout << Endl;
}
Main ()
{
MULTIPLY ("177856", "196196");
}