fork(1) download
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. double Xn = 1, Sn = 0, epsilon; unsigned int n = 0;
  8. cin >> epsilon;
  9. while (Xn >= epsilon)
  10. {
  11. n++;
  12. Xn *= 2.0 / (n+1);
  13. Sn += Xn;
  14. }
  15. cout << fixed << setprecision(15) << n << " " << Sn << endl;
  16. return 0;
  17. }
Success #stdin #stdout 0s 3464KB
stdin
30
stdout
0 0.000000000000000