杭电1042

最好在main()函数外声明a[M]
#include "stdio.h"
#include "string.h"
#define M 50000
int a[M];
main()
{
	int n,i,j,c,temp;
	while(scanf("%d",&n)!=EOF)
	{
		c = 0;
		memset(a,0,sizeof(a));
		a[0] = 1;
		for(i=1; i<=n; i++)
		{
			for(j=0; j<M; j++)
			{				
				temp = a[j] * i + c;
				a[j] = temp%10;
				c = temp/10;
			}
		}
		j = M-1;
		while(!a[j])	{j--;	}
		while(j>=0)		{printf("%d",a[j--]);}
		printf("\n");
	}
}

你可能感兴趣的:(杭电1042)