1大数据乘法的算法思路:
输入两个字符串,得到结果,例如:123456789*123456789;
思路:1)首先
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
依次相乘相加;
2)再进位;
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> void big_data_multi (char *pstr1, char *pstr2) { int length_str1 = strlen(pstr1); int length_str2 = strlen(pstr2); int *pstr3 = (int*)malloc(sizeof(int)*(length_str1+length_str2)); memset(pstr3, 0, sizeof(int)*(length_str1+length_str2));//一定要初始化,否则乱码 for(int i = 0; i < length_str2; i++)//循环累乘相加 { for(int j = 0; j < length_str1; j++) { pstr3[i + j + 1] += (pstr1[j] - '0') * (pstr2[i] - '0'); } } for (int i = length_str1 + length_str2 - 1; i >= 0; i--) { if(pstr3[i] >= 10) { pstr3[i - 1] += pstr3[i] / 10; pstr3[i] = pstr3[i]%10; } } int i = 0; while (pstr3[i] == 0) { i++; } char *pstr4 = (char*)malloc(sizeof(char)*(length_str1 + length_str2 + 1)); int j = 0; for(; j < length_str1+length_str2 && i < length_str1+length_str2; j++,i++) { pstr4[j] = pstr3[i] + '0'; } pstr4[j] = '