www.gsyw.net > 计算并输出下列级数和s=1+1/(1+2)+1/(1+2+3)+...+1/(1+2+3+...+n...

计算并输出下列级数和s=1+1/(1+2)+1/(1+2+3)+...+1/(1+2+3+...+n...

#include <iostream> using namespace std; int main() { int n; //存储n的值 double s=0; //存储结果 int i=1; //用来计数 cout << "请输入s的值:"; cin >> n; while(i<=n) { s = s + 1.0/(i*(i+1)); i++; } cout << "计算的结果是:" << s << endl; return 0; }

#include<stdio.h> int main() { int n=2,i; float sum=0; for(i=1;i<=n;i++) sum=sum+(float)1/(i*(i+1)); printf("sum=%f\n",sum); } 在vc6 下运行成功了 拿去用吧 别忘了采纳

#include <iostream>#include <vector> using namespace std; double s(int n); double sumi(int n); int main() { cout<<s(50)<<endl; //求前50项的和 } double sumi(int n) { double sum=0; for(int i=0;i<n;i++,sum+=i); return sum; } double s(int n) { double

Dim n As Integers = 0 '累加器清零For n = 0 To 200s = s + n / (1 + n * n)'累加Next nPrint Format(s, "0.0") '取一位小数

#include int main(void){int n;int i,j;float sum = 1.0;float dex = 1.0;printf("输入一个数:");scanf("%d",&n);for (i = 2; i 0; --j){dex*=j;}sum+=1/dex;dex = 1.0;}printf("%.2f\n",sum);return 0;}

printf("%d",s); 改成 printf("%f",s);

很简单的: #include <stdio.h> double fun(int n) { double s=0,t=0; int i; for(i=1;i<=n;i++) { t+=i; s+=1.0/t; } return s; } void main() { int n; printf("输入n值:"); scanf("%d",&n); printf("%lf\n",fun(n)); }

#include<stdio.h> main() { int n,i,j,sum=0; scanf("%d",&n); for(i=1;i<=n;i++){ for(j=1;j<=i;j++){ sum+=j; } } printf("%d\n",sum); } 扩展资料:printf函数使用注意事项1、域宽%d:按整型数据的实际长度输出.如果想输出指定宽度可以指定域宽,

相关搜索:

网站地图

All rights reserved Powered by www.gsyw.net

copyright ©right 2010-2021。
www.gsyw.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com