基础编程题目集 6-10 阶乘计算升级版 (20分)
程序员文章站
2022-03-13 13:47:16
...
#include <stdio.h>
void Print_Factorial(const int N);
int main()
{
int N;
scanf("%d", &N);
Print_Factorial(N);
return 0;
}
void Print_Factorial(const int N)
{
if (N < 0)
{
printf("Invalid input\n");
return;
}
int d[40000];
d[0] = 1;
int t = 0, tmp = 0, carry = 0;
for (int i = 1; i <= N; i++)
{
for (int j = 0; j <= t; j++)
{
tmp = d[j] * i + carry;
d[j] = tmp % 10;
carry = tmp / 10;
}
while (carry != 0)
{
d[++t] = carry % 10;
carry /= 10;
}
}
for (int i = t; i >= 0; i--)
{
printf("%d", d[i]);
}
printf("\n");
}
上一篇: 数据结构和算法:06.递归和栈结构
下一篇: 7-8 螺旋方阵 (20分)