阶乘
// 阶乘 #include<iostream> const int maxn = 3000; int fac[maxn],len; void fact(int n){ int i,j; memset(fac,0,sizeof(fac)); fac[0]=1; for(i=2;i<=n;i++){ int ten=0; for(j=0;j<maxn;j++){ int one=fac[j]*i+ten; fac[j]=one%10; ten=one/10; } } for(j=maxn-1;j>=0;j--) if(fac[j]) break; len=j+1; } void wofa(int n){ int i; fact(n); for(i=len-1;i>=0;i--) printf("%d",fac[i]); printf("\n"); } int main() { int n; scanf_s("%d", &n); wofa(n); system("pause"); return 0; }