c语言计算1997的阶乘
时间: 2024-06-10 12:01:13 浏览: 88
C语言求阶乘
以下是C语言计算1997的阶乘的代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 10000
int main()
{
int a[MAX], i, j, n, temp, m = 1;
memset(a, 0, sizeof(a));
a[0] = 1;
for (i = 1; i <= 1997; i++)
{
temp = 0;
for (j = 0; j < m; j++)
{
n = a[j] * i + temp;
a[j] = n % 10;
temp = n / 10;
}
while (temp > 0)
{
a[m] = temp % 10;
temp = temp / 10;
m++;
}
}
printf("1997! = ");
for (i = m - 1; i >= 0; i--)
{
printf("%d", a[i]);
}
printf("\n");
return 0;
}
```
阅读全文