标签:
//输出100的阶乘 使用字符串存入阶乘的结果 然后每一位一次计算结果。
#include<iostream>
#include<string>
using namespace std;
int main()
{
string a = "1";
for (int i = 1; i < 100; i++)
{
int y = 0;
for (int j = 0; j < a.length(); j++)
{
int x = (int)(a[j] - ‘0‘);
x = x*i;
x = x + y;
y = x / 10;
x = x % 10;
a[j] = (char)(x + ‘0‘);
}
while (y)
{
a = a + (char)((y % 10)+‘0‘);
y = y / 10;
}
for (int k = a.length() - 1; k >= 0; k--)
{
cout << a[k];
}
cout << endl;
}
return 0;
}


标签:
原文地址:http://www.cnblogs.com/3712k/p/5485335.html