This commit is contained in:
2026-06-15 09:00:38 +08:00
parent fec66377d5
commit 4640c5e02b
191 changed files with 6046 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
#include <stdio.h>
#include <string.h>
#define MAX_LEN 1000
// 计算两个大整数的乘积
void multiply(const char* a, const char* b, char* result) {
int lenA = strlen(a), lenB = strlen(b), lenResult = lenA + lenB;
int arr[MAX_LEN * 2] = {0};
// 进行乘法运算
for (int i = 0; i < lenA; ++i)
for (int j = 0; j < lenB; ++j)
arr[i + j] += (a[lenA - i - 1] - '0') * (b[lenB - j - 1] - '0');
// 处理进位
for (int i = 0; i < lenResult - 1; ++i) {
arr[i + 1] += arr[i] / 10;
arr[i] %= 10;
}
// 构建结果字符串
int index = 0;
while (index < lenResult && arr[index] == 0) ++index;
if (index == lenResult) strcpy(result, "0");
else {
for (int i = index; i < lenResult; ++i)
result[i - index] = arr[lenResult - i - 1] + '0';
result[lenResult - index] = '\0';
}
}
int main() {
char a[MAX_LEN + 1], b[MAX_LEN + 1], result[MAX_LEN * 2 + 1];
printf("输入第一个大整数: ");
scanf("%s", a);
printf("输入第二个大整数: ");
scanf("%s", b);
multiply(a, b, result);
printf("结果: %s\n", result);
return 0;
}