c语言练习25——求 1+2!+3!+4!……n!的和

 1 #include
 2 #include
 3 //题目:求 1+2!+3!+4!……n!的和
 4 int main(){
 5 int s,i,n,a,sum;
 6 while(1){
 7 printf("请输入参数n:");
 8 scanf("%d",&n);
 9 sum=0;
10 for(i=1;i<=n;i++){
11     s=1;
12     for(a=1;a<=i;a++)
13     s=s*a;
14     sum=sum+s;
15     }
16 printf("1+2!+3!+……+%d!=%d\n________________________________\n",n,sum);
17 }
18 return 0;
19 }
20    

 

转载于:https://www.cnblogs.com/gougouwang/p/11411643.html

你可能感兴趣的:(c语言练习25——求 1+2!+3!+4!……n!的和)