文章
36
粉丝
505
获赞
55
访问
370.5k
用数组模拟高精度
#include<cstring>//memset(s, 0, sizeof(s))
#include<iostream>
using namespace std;
int c[100000];
int main()
{
int n;
while (cin >> n)
{
memset(c, 0, sizeof(c));
int w = 1;//记录位数
c[1] = 1;
for (int i = 2; i <= n; i++)
{
for (int j = 1; j <= w; j++)
c[j] *= i;
for (int j = 1; j <= w; j++)
{
if (c[j] > 9)
{
c[j + 1] += c[j] / 10;
c[j] %= 10;
if (j == w)
w++;
}
}
}
for (int i = w; i >= 1; i--)
cout << c[i];
cout << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发