大数相乘练习
#include <iostream> #include <memory> using namespace std; int* BigNumberMulti(int arr1[], int length1, int arr2[], int length2) { int len = length1 + length2; int* ret = new int[len]; memset(ret, 0, sizeof(int)*len); for (int i = 0; i < length1; i++) { int x = i; for (int j = 0; j < length2; j++) { ret[x++] += arr1[i] * arr2[j]; } } for (int k = 0; k < len-1; k++) { if (ret[k] > 10) { ret[k + 1] += ret[k] / 10; ret[k] = ret[k] % 10; } } return ret; } int main() { int arr1[] = { 1,2,3,4,5,6,7,8,9 }; int arr2[] = { 9,8,7,6,5,4,3,2,1 }; int len1 = sizeof(arr1) / sizeof(arr1[0]); int len2 = sizeof(arr2) / sizeof(arr2[0]); int resultLen = len1 + len2; int* result = BigNumberMulti(arr1, len1 , arr2, len2); for (int i = resultLen -1; i >= 0; i--) { cout << result[i] << " " ; } cout << endl; delete[] result; return 0; }
作 者: itdef
欢迎转帖 请保持文本完整并注明出处
技术博客 http://www.cnblogs.com/itdef/
B站算法视频题解
https://space.bilibili.com/18508846
qq 151435887
gitee https://gitee.com/def/
欢迎c c++ 算法爱好者 windows驱动爱好者 服务器程序员沟通交流
如果觉得不错,欢迎点赞,你的鼓励就是我的动力
欢迎转帖 请保持文本完整并注明出处
技术博客 http://www.cnblogs.com/itdef/
B站算法视频题解
https://space.bilibili.com/18508846
qq 151435887
gitee https://gitee.com/def/
欢迎c c++ 算法爱好者 windows驱动爱好者 服务器程序员沟通交流
如果觉得不错,欢迎点赞,你的鼓励就是我的动力


【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步