C--計算求1+2!+3!+.......+n!
阿新 • • 發佈:2018-11-12
求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;//給和賦初值為011 //二重迴圈迴圈遍歷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