发布网友 发布时间:2022-10-10 09:42
共1个回答
热心网友 时间:2023-10-07 05:49
2000的阶乘都能算
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void factorial(int n, char *pout) {
if (pout == NULL) {
return;
}
int arr[20001];
int idx = 1;
arr[0] = 1;
for (int i = 1; i <= n; i++) {
int cry = 0;
for (int j = 0; j < idx; j++) {
arr[j] = arr[j] * i + cry;
cry = arr[j] / 10;
arr[j] %= 10;
}
while (cry > 10) {
arr[idx++] = cry % 10;
cry /= 10;
}
if (cry > 0)
arr[idx++] = cry;
}
for (int i = idx - 1; i >= 0; i--) {
*pout++ = arr[i] + '0';
}
*pout = '\0';
return;
}
int main() {
char buff[20000] = {0};
int n = 0;
scanf("%d", &n);
factorial(n, buff);
puts(buff);
return 0;
}