Find the exact value

Find the smallest positive integer n, such that 1 / n and 1 / (n + 1) is less than the difference 0.0000001. And output n 1 / n, 1 / (n + 1), 8 bits are decimal.

#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
 int n=1;
 double x;
 do
 {
  n++;
  x=1.0/n-1.0/(n+1);
 }
 while(x>=0.0000001);
 cout<<fixed<<setprecision(8);
 cout<<n<<"\n"<<1.0/n<<"\n"<<1.0/(n+1);
}
Published 109 original articles · won praise 97 · views 5113

Guess you like

Origin blog.csdn.net/huangziguang/article/details/104819298