BigNumber BigNumber::Multiply(const BigNumber &b){ flag carry = FALSE, Bigger = FALSE, Zeros = FALSE; long temp = 0, Check = 0; int Ccount = 0, MultCount = 1, i, j, StrSize = 0, Max = 0; Zeros = CheckIfZero(b); if (Zeros == TRUE){ //if a or b's strings are all zeros, the result will be zero. BigNumber Temp; return Temp; } int tempstr[MaxSTR]; for (int i = 0; i= 0; j--){ MultCount++; Max = MaxSTR; for (i = size - 2; i >= 0; i--){ temp = (str[i] - '0')*(b.str[j] - '0'); if (carry == TRUE) { while (Ccount != 0) { temp++; Ccount--; } carry = FALSE; } while (temp > 9 && i != 0) { temp -= 10; Ccount++; carry = TRUE; } if (i != 0) //as long as it is not the last number { Check = (tempstr[Max - MultCount] + temp); if (Check < 10) tempstr[Max - MultCount] += temp; else{ int index = Max - MultCount; while (tempstr[index] + temp > 9) { tempstr[index] = tempstr[index] + temp - 10; Ccount++; carry = TRUE; } } Check = 0; } else { //if it is the last number it will add the carry temp += Ccount; Ccount = 0; tempstr[Max - MultCount] += temp; while (tempstr[Max - MultCount] > 9) { tempstr[Max - MultCount] -= 10; tempstr[Max - MultCount - 1]++; } } Max--; temp = 0; } } } else { for (j = size - 2; j >= 0; j--){ MultCount++; Max = MaxSTR; for (i = b.size - 2; i >= 0; i--){ temp = (str[i] - '0')*(b.str[j] - '0'); if (carry == TRUE) { while (Ccount != 0) { temp++; Ccount--; } carry = FALSE; } while (temp > 9 && i != 0) { temp -= 10; Ccount++; carry = TRUE; } if (i != 0) //as long as it is not the last number { Check = (tempstr[Max - MultCount] + temp); if (Check < 10) tempstr[Max - MultCount] += temp; else{ int index = Max - MultCount; while (tempstr[index] + temp > 9) { tempstr[index] = tempstr[index] + temp - 10; Ccount++; carry = TRUE; } } Check = 0; } else { //if it is the last number it will add the carry temp += Ccount; Ccount = 0; tempstr[Max - MultCount] += temp; while (tempstr[Max - MultCount] > 9) { tempstr[Max - MultCount] -= 10; tempstr[Max - MultCount - 1]++; } } Max--; temp = 0; } } } StrSize = Getsize(b); BigNumber Temp(StrSize); j = 0; for (i = (MaxSTR - StrSize); i < MaxSTR-1; i++) { Temp.str[j] = (tempstr[i] + '0'); j++; } Temp.str[StrSize - 1] = '\0'; return Temp; }