#include <stdio.h>
void Print_Factorial ( const int N );
int main()
{
int N;
scanf("%d", &N);
Print_Factorial(N);
return 0;
}
void Print_Factorial ( const int N )
{
if(N<13)
{
int plus=1;
for(int i=2;i<=N;i++)
plus*=i;
printf("%d",plus);
}
else
{
int n=0,k=1,temp;
int a[3000]={1};
for(int i=2;i<=N;i++)
{
for(int j=0;j<k;j++)
{
temp=a[j]*i+n;
a[j]=temp%10;
n=temp/10;
}
while(n!=0)
{
a[k]=n%10;
k++;
n/=10;
}
}
for(int i=k-1;i>=0;i--)
printf("%d",a[i]);
}
}
k是数字位数,n是向下一位进位的数
每一位都进行乘法运算后,若n不为0,k++。