#include <iostream>
using namespace std;
const int MAX_LEN = 10000;
int main()
{
while(1)
{
cout << "Enter the number n: ";
int n;
cin >> n;
int result[MAX_LEN];
memset(result, 0, MAX_LEN);
result[0] = 1;
result[1] = 1;
for( int num = 2; num <= n; ++num ) // result = result * num
{
int temp = 0;
int carry = 0;
for( int i = 1; i <= result[0]; ++i)
{
temp = num * result[i] + carry; //计算当前位与 num 的乘积
result[i] = temp % 10; //计算余数
carry = temp / 10; //计算进位
}
while(carry > 10)
{
result[++result[0]] = carry % 10;
carry /= 10;
}
if(carry)
result[++result[0]] = carry;
}
cout << endl << n <<"! = ";
for( int i = result[0]; i > 0; --i)
{
cout << result[i];
}
cout << "(共 " << result[0] << " 位)";
if(result[0] >= MAX_LEN)
cout << "存储溢出,结果不保证!" << endl;
cout << endl << endl;
}
return 0;
}