杭电OJ-1042_N!

求N的阶乘,要算大数,所以要模拟手算

#include<iostream>
using namespace std;
int a[50000],n;
int main()
{	
	while (cin >> n)
	{
		memset(a,0,50000);
		a[0] = 1;
		a[1] = 1;
		for (int i = 2; i <= n; i++)
		{
			for (int j = 1; j <= a[0]; j++)
				a[j] *= i;
			for (int k = 1; k <= a[0]; k++)
			{
				if (a[k] > 9)
				{
					if (k == a[0]) a[0]++;
					a[k + 1] += a[k] / 10;
					a[k] = a[k] % 10;	
				}
			}

		}
		for (int l = a[0]; l >= 1; l--)
			cout << a[l];
		cout << endl;
	}
}


posted @ 2015-07-24 18:26  A_yes  阅读(176)  评论(0编辑  收藏  举报