[c++]代码库
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int arr[10000] = {0}, a, brr[10000] = {0};
while(cin >> a)
{
int count = 1, count1 = 1; ///count为阶乘数组位数,count1为结果数组位数;
memset(arr, 0, sizeof(arr));
memset(brr, 0, sizeof(brr));
arr[0] = 1;
for(int i = 1; i <= a; i++)
{
///阶乘
for(int j = 0; j < count; j++)
{
arr[j] *= i;
}
for(int j = 0; j < count; j++)
{
if(arr[j] >= 10)
{
arr[j + 1] += arr[j] / 10;
arr[j] %= 10;
}
}
while(arr[count])
{
arr[count + 1] += arr[count] / 10;
arr[count] %= 10;
count++;
}
///plus
count1 = count;
for(int i = 0; i < count; i++)
{
brr[i] += arr[i];
if(brr[i] >= 10)
{
brr[i + 1] += brr[i] / 10;
brr[i] %= 10;
}
}
while(brr[count1])
{
brr[count1 + 1] += brr[count1] / 10;
brr[count1] %= 10;
count1++;
}
}
for(int i = count1 + 1; i >= 0; i--) ///输出
{
if(brr[i] != 0)
{
for(int j = i; j >= 0; j--)
cout << brr[j];
cout << endl;
break;
}
}
}
return 0;
}
[代码运行效果截图]