99问答网
所有问题
用c++求1+1/2+1/3+1/4+1/n的近似值,要求至少累加到1/n不大于0.00984为止,输出循环次数的累加和
如题所述
举报该问题
推荐答案 2018-04-10
#include <stdio.h>
int main()
{int n;
double s=0;
n=1;
do
{s+=1.0/n;
}while(1.0/n++>0.00984);
printf("n=%d\ns=%.8lf\n",--n,s);
return 0;
}
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://99.wendadaohang.com/zd/WtBvOeWtjB7evtOW7Bj.html
相似回答
大家正在搜
相关问题
用c++求1+1/2+1/3+1/4+1/n的近似值,要求至...
c++,写一函数用递归方法求:1+1/2+1/3+1/4+1...
c++程序设计设s=1+1/2+1/3+....+1/n,求...
while循环求,1+1/2+1/3+1/4…..1/n>1...
C++问题,y=1+1/2+1/3+1/4+......+1...
C语言编写函数求:1-1/2+1/3-1/4+1/5-1/6...
编写程序,求e的值。e≈1+1/1!+1/2!+1/3!+1...
C++ 按下列公式,求e的近似值。e=1+1/1!+1/2!...