One: Code implementation
Big Data multiplication operations # include <stdio.h> #include <stdlib.h> #include <string.h>int bigdatamul (char *num01, char * NUM02) {int res = 0, i = 0, j = 0;int length01 = 0, length02 = 0, totallength = 0;if (NULL = = NUM01 | | NULL = = num02) {res = -1;return res;} LENGTH01 = strlen (NUM01); length02 = strlen (num02); totallength = length01 + length02;int *presult = (int *) malloc (sizeof (in T) * totallength); memset (presult, 0, sizeof (int) * totallength); if (NULL = = presult) {res = -2;return res;} Multiplicative for (i = 0; i < length01; i++) {for (j = 0; J < length02; J + +) {//To empty the first bit in case of a carry, note this No. 0 position, indicating the highest presult[i + j + 1] + = (Num01[i]-' 0 ') * (Num02[j]-' 0 ');}} Additive reverse for (i = totallength-1; I >= 0; i--) {//greater than 10 means to produce carry if (Presult[i] >=) {presult[i-1] + = Presult[i]/10;//Fetch Carry Presult[i]%= 10;//remove the single digit}}i = 0;//Remove the preceding 0, because there may not be a carry, the front may be 0while (0 = = Presult[i]) {i++;} may be multiplied by 0, the result is all 0if (i = = totallength + 1) {printf ("0\n"); goto Iszero;} Char *plastresult = (char *) malloc (sizeof (char) * totallength); memset (PLAStresult, 0, sizeof (char) * totallength); if (NULL = = Plastresult) {res = -2;return res;} for (j = 0; i < totallength; i++, J + +) {plastresult[j]= presult[i] + ' 0 ';} for (i = 0; i < totallength; i++) {printf ("%c", Plastresult[i]);} Free (plastresult);p Lastresult = Null;iszero:free (presult);p result = Null;return res;} int main (int argc, char *argv[]) {Bigdatamul ("22222", "9"); return 0;}
Big Data multiplication