1 #include<stdio.h> 2 #include<stdlib.h> 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
时间: 2024-10-14 07:09:02