#include <iostream>
using namespace std;
void Bigdigital(int n, int a[])
{
int len = 1;//目前已经存储在数组的数字个数
int j = 0;
for (int i = 2; i <= n; ++i)//阶乘数字
{
int d = 0;//进位
for (j = 1; j <= len; ++j)
{
int b = a[j] * i + d;
a[j] = b % 1000000;
d = b / 1000000;
}
if (d != 0)
{
a[j] = d;
len = len + 1;
}
}
}
void output(int a[])//注意中间的数字要补0
{
int flag = 0;
for (int i = 27; i >= 1; --i)
{
if (flag == 0)
{
if (a[i] == 0)
{
continue;
}
else
{
flag = 1;
int c1 = a[i] % 10;
int c2 = (a[i] / 10) % 10;
int c3 = (a[i] / 100) % 10;
int c4 = (a[i] / 1000) % 10;
int c5 = (a[i] / 10000) % 10;
int c6 = (a[i] / 100000) % 10;
cout << c6 << c5 << c4 << c3 << c2 << c1 << endl;
}
}
else {
int c1 = a[i] % 10;
int c2 = (a[i] / 10) % 10;
int c3 = (a[i] / 100) % 10;
int c4 = (a[i] / 1000) % 10;
int c5 = (a[i] / 10000) % 10;
int c6 = (a[i] / 100000) % 10;
cout << c6 << c5 << c4 << c3 << c2 << c1 << endl;
}
}
}
int main()
{
int n = 0;
int a[28] = { 0 };
a[1] = 1;
cout << "请输入您希望计算的阶乘: ";
cin >> n;
Bigdigital(n, a);
output(a);
system("pause");
return 0;
}
有任何问题欢迎大家指出,大家一起探讨~