大数阶乘

#include<stdio.h>
int main()
{
	int n, i, j, t, digit=1, count, k, temp, a[1000];//digit 表示结果是几位数
	//count 表示进位比如7*6 = 42 进位就是4
		scanf("%d",&n);//要求的阶乘
	a[0] = 1;
	for(i = 2; i <= n; i++)
	{
		for(count = 0, j = 1;j <= digit; j++ )
		{
			temp = a[j-1] * i + count;//每个位数上的数都要乘以i+进位
			a[j-1] = temp % 10;//每个位数上的数为结果%10 
			count = temp / 10;//进位为结果除于10
		}
		while(count)//进位>0
		{
			digit++;//结果的位数+1
			a[digit-1] = count%10;//进位也许是>10的所以要对十取余
			count = count / 10;
		}
	}
	for(k = digit; k >= 1; k--)
		printf("%d",a[k-1]);
}
posted @ 2016-04-03 11:59  云胡同学  阅读(132)  评论(0编辑  收藏  举报