1 algorithm ideas for big data multiplication:
Enter two strings to get the result, for example: 123456789*123456789;
Ideas: 1) First
123456789*1 = 9 18 27 36 45 54 63 72 81
123456789*2 = 9 18 27 36 45 54 63 72 81
123456789*3 = 9 18 27 36 45 54 63 72 81
123456789*4 = 9 18 27 36 45 54 63 72 81
123456789*5 = 9 18 27 36 45 54 63 72 81
123456789*6 = 9 18 27 36 45 54 63 72 81
Multiply and add in sequence;
2) re-rounding;
#define_crt_secure_no_warnings#include<stdio.h>#include<stdlib.h>#include<string.h>voidBig_data_multi (Char*PSTR1,Char*pstr2) { intLENGTH_STR1 =strlen (PSTR1); intLENGTH_STR2 =strlen (PSTR2); int*PSTR3 = (int*)malloc(sizeof(int) * (length_str1+length_str2)); memset (PSTR3,0,sizeof(int) * (LENGTH_STR1+LENGTH_STR2));//Be sure to initialize, otherwise garbled for(inti =0; i < LENGTH_STR2; i++)//Cyclic multiplicative addition { for(intj =0; J < Length_str1; J + +) {Pstr3[i+ j +1] + = (pstr1[j)-'0') * (Pstr2[i]-'0'); } } for(inti = length_str1 + LENGTH_STR2-1; I >=0; i--) { if(Pstr3[i] >=Ten) {Pstr3[i-1] + = Pstr3[i]/Ten; Pstr3[i]= pstr3[i]%Ten; } } inti =0; while(Pstr3[i] = =0) {i++; } Char*PSTR4 = (Char*)malloc(sizeof(Char) * (LENGTH_STR1 + length_str2 +1)); intj =0; for(; J < length_str1+length_str2 && i < length_str1+length_str2; j++,i++) {Pstr4[j]= Pstr3[i] +'0'; } Pstr4[j]=' /'; printf ("The result of multiplying is:%s\n", PSTR4);}intMain () {Charstr1[ -] = {0},str2[ -] = {0}; while(1) {gets (STR1); printf ("str1 =%s\n", STR1); Gets (STR2); printf ("str2 =%s\n", STR2); Big_data_multi (str1, str2); } System ("Pause");}
Multiplication of big data implements--C language