第一次写文章,如有不好的地方,请多多包涵,并在评论区提出意见。
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[35665]={0},b[35665]={0},i,n,t,h=1;
cin>>i;
a[0]=b[0]=1;//初始化
for(n=2;n<=i;n++){
for(t=0;t<h;t++)a[t]*=n;//各数位乘n
for(t=0;t<h;t++){
if(a[t]>9){
if(t==h-1)h++;
a[t+1]+=a[t]/10;
a[t]%=10;
}
}//计算n的阶乘
for(t=0;t<h;t++){//累加阶乘
b[t]+=a[t];
if(b[t]>9){
b[t+1]++;
b[t]-=10;
}
}
}
for(n=h-1;n>=0;n--)cout<<b[n];//输出阶乘和
return 0;
}
网上查了查,发现都是用自定义函数的,感觉自己被孤立了……
有没有大神和我解法一样的?放到评论区一起讨论吧!(全球这么多人,肯定有和我一模一样的)