C--计算求1+2!+3!+.......+n!

求1+2!+3!+.......+n!

代码;

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 5 void main(){
 6     
 7     int s;//和为s 
 8     int n;
 9     scanf("%d",&n);
10     s=0;//给和赋初值为0 
11     //二重循环循环遍历i,j 
12     int i;
13     int j;
14         int t;//计算每个数阶乘的值 
15     for(i=1;i<=n;i++){
16         t=1;
17         for(j=1;j<=i;j++)
18         {
19             t=t*j;
20         } 
21         s=s+t;
22         }
23     
24         printf("和为%d",s);
25 }
26                                                                                                                                                                        
1+2!+3!+......+n!

猜你喜欢

转载自www.cnblogs.com/Catherinezhilin/p/9945937.html