用c++作1+1/2+1/3+1/4+....1/n等于多少

用c++作1+1/2+1/3+1/4+....1/n等于多少

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
double sum=0.0;
int n;
cin>>n;
for(int i=1;i<=n;i++){
    sum+=1.0/i;
}
cout<<setprecision(2) <<std::fixed <<sum;
    return 0;
}

温馨提示:内容为网友见解,仅供参考
无其他回答

用c++作1+1\/2+1\/3+1\/4+...1\/n等于多少
include <iostream>#include <cmath>#include <iomanip>using namespace std;int main(){double sum=0.0;int n;cin>>n;for(int i=1;i<=n;i++){ sum+=1.0\/i;}cout<<setprecision(2) <<std::fixed <<sum; return 0;} ...

1+1\/2+1\/3+1\/4+...+1\/n怎么求和?
当n很大时,有:1+1\/2+1\/3+1\/4+1\/5+1\/6+...1\/n = 0.57721566490153286060651209 + ln(n)\/\/C++里面用log(n),pascal里面用ln(n)0.57721566490153286060651209叫做欧拉常数 to GXQ:假设;s(n)=1+1\/2+1\/3+1\/4+..1\/n 当 n很大时 sqrt(n+1)= sqrt(n*(1+1\/n))= sqrt(n)*s...

用C\\C++语言编写1+1\/2!+1+3!+...1\/n!求值,帮帮我啊~~
double sumb(int n){ int i,t = 1;double sumb = 0;for(i=1;i<=n;i++){ t *= i;sum+=1.0\/ t;} } void main(){ int n;scanf("%d",&n);printf("1+1\/2!+1\/3!+...1\/n!的值为:%f",sumb(n));}

c++计算1+1\/2+1\/3+...+1\/n
define n 100 float f(float a){float b;b=1.0\/a;return b;} main(){float sum=0;int i=1;for(i=1;i<n;i++)sum+=f((float)i);printf("%lf",sum);} 你先这么整吧,你那个我CPP运行不了

c++程序设计设s=1+1\/2+1\/3+...+1\/n,求与八最接近的s的值与其对应的n值...
取小者(相等时取前一项)的最后一项的n便是题解。代码如下:include "stdio.h"int main(int argc,char *argv[]){int n;double s;s=n=0;do{s+=1.0\/++n;}while(s<8);if(s-8 > 8-s+1.0\/n)s-=1.0\/n--;printf("s = %f\\tn = %d\\n",s,n);return 0;}运行结果如下:...

求助!!c++程序设计设s=1+1\/2+1\/3+...+1\/n,求与八最接近的s的值与其对...
double)(1.0\/n) ;n++ ;}while(s<8) ; \/\/退出循环的时候,s大于8,s2小于等于8 if(8-s2>s-8) \/\/算绝对值。。。小的输出 cout<<"s="<<s<<" n="<<n-1<<endl ;else cout<<"s="<<s2<<" n="<<n-2<<endl ; \/\/输出 return 0 ; \/\/return 0;} ...

用C++编程s=1+1\/2!+1\/3!+1\/4!+……+1\/n 求恰好使s大于x的值 (急呀...
直接上代码如下,因为代码用到了阶乘,注意不要溢出。include <iostream> long greatherThan(double x){ double s = 0.0f;long result = 1;long temp = 1;while(s < x){ temp = temp * result;s += (1.0 \/ temp);result++;} return result - 1;} int main(){ std::cout << ...

用c++求1+1\/2+1\/3+1\/4+1\/n的近似值,要求至少累加到1\/n不大于0.00984为止...
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;}

数列求和 1+1\/2+1\/3+1\/4+1\/5+……1\/n=? 急~
利用“欧拉公式:1+1\/2+1\/3+……+1\/n=ln(n)+C,C为欧拉常数数值是0.5772……则1+1\/2+1\/3+1\/4+...+1\/2007+1\/2008=ln(2008)+C=8.1821(约)就不出具体数字的,如果n=100 那还可以求的 。然而这个n趋近于无穷 ,所以算不出的。它是实数,所以它不是有理数就是无理数,而上...

C++算1\/1!++1\/2!+1\/3!+...+1\/N!
\/\/ Note:Your choice is C++ IDE include <iostream> include <iomanip> using namespace std;int main(){ double i,s=0.0;double k(int j);int n;cout<<"please input a number n ";cin>>n;for(i=1;i<=n;i++)s=1\/k(i)+s;cout<<"1\/1!+1\/2!+……+1\/"<<n<<"!= ...

相似回答