#define NUM 3000
#include<stdio.h>
int main()
{
int nNum = 0;
//存储1000阶乘数据:
int aryBuff[NUM] = { 0 };
//初始化最数组为下标为0,为1:
aryBuff[0] = 1;
printf("请输入阶乘:\n");
scanf_s("%d",&nNum);
//遍历1-nNum的因子:
for (int i = 2; i <= nNum; i++)
{
//临时需要进位的值:
int nTemp = 0;
//进位:
int nCarryOver = 0;
for (int j = 0; j < NUM; j++)
{
nTemp = i * aryBuff[j] + nCarryOver;
//需要进位:
aryBuff[j] = nTemp % 10;
//在去他下一个进位:
nCarryOver = nTemp / 10;
}
}
//如果第一个不为0的数,的下标:
int index = 0;
//遍历数组,查找第一个不为0的数
for (int i = NUM - 1; i > 0; i--)
{
if (aryBuff[i]!=0)
{
index = i;
break;
}
}
printf("打印%d的阶乘值为:",nNum);
for (int j = index; j >0; j--)
{
printf("%d",aryBuff[j]);
}
return 0;
}