hyfm.net
当前位置:首页 >> 编写C语言程序,输入一个整数n(n<=10),求sum=1!+2!+3!+.....+n! >>

编写C语言程序,输入一个整数n(n<=10),求sum=1!+2!+3!+.....+n!

#include"stdio.h" main() { int n,i; long s=0,sum=1; scanf("%d",&n); for(i=1;i<=n;i++) { sum=sum*i; s=s+sum; } printf("%ld",s); } 好了,就这样,不复杂

楼主你好!根据你要求实现如下#include<stdio.h> int fun(int n){ if(n>0)return n*fun(n-1); return 1; } int main(){ int n,i,sum=0; printf("请输入n(n<10):"); scanf("%d",&n); for(i=1;i<=n;i++){ sum=sum+fun(i); } printf("sum=%d\n",sum); return 0; } 希望我的回答对你有帮助!

源程序如下: #include <stdio.h> int main() { int n,i,j,sum=1,t; scanf("%d", &n); for(i=1;i<=n;i++) { t=1; for(j=1;j<=i;j++) { t *= 2; //每次计算2 ^ i 出来 } sum += t; //sum加上算出来的2 ^ i } printf("%d\n", sum); return 0; }

#include int main(void) { int n; int i = 0, sum = 0; scanf("%d", &n); for (i = 0; i sum += i + i + 1; } printf("%d", sum); return 0; }

main() { int i,j,k; float sum=0; clrscr(); scanf("%d",&n); if(n>=3&&n{ for(i=1;i {k=1; for(j=1;j k=k*j; sum=sum+1.0/k; } printf("%d",sum); } else printf("wrong"); }

#include<stdio.h>double fac(int n){double f=1; for(;n;)f*=n--; return f;}int main(){int i,n; double s=0; scanf("%d",&n); for(i=1;i<=n;i++) s+=fac(i); printf("%.0lf\n",s); return 0;}

#include<stdio.h> int main() { int n; double sum=0;//记录总和初始值为0 printf("输入n的值:"); scanf("%d",&n); for(int i=1;i<=n;i++)sum+=1.0/i; printf("前n项之和为:%lf\n",sum); return 0; } 运行通过,可用.

1. 使用c语言编程输入整数n,求1+2+3+……+n和n! #include<stdio.h>#include<math.h>int main(){int i;int nNumber;int nSum = 0;printf("Input Data:'N'");scanf("%d", &nNumber);for ( i = 1; i <= nNumber; i++){nSum = nSum + i;}printf("%d\r\n",

#include void main(void){ int n,i; unsigned sum=0; printf("Type a number\nn="); scanf("%d",&n); for(n++,i=1;i printf("1^2+2^2+3^2++n^2=%ld\n",sum); }

include<stdio.h> int main() { int fun(int n); int i,n,sum=0; scanf("%d",&n); if(n<=0||n>=10) { prinntf("Error ,Input the value of 1 to 9!\n"); return 0; } for(i=1;i<n;i+=2) sum+=fun(i); sum+=fun(n); printf("%d\n",sum); return 0; } int fun(int n)

相关文档
网站首页 | 网站地图
All rights reserved Powered by www.hyfm.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com