fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. double c, eps;
  6. cin >> c >> eps;
  7.  
  8. // poprawny przedziaƂ dla c > 1
  9. double a = 1.0;
  10. double b = c;
  11. double m;
  12.  
  13. // metoda bisekcji
  14. while (b - a > eps) {
  15. m = (a + b) / 2.0;
  16.  
  17. if (m * m > c)
  18. b = m;
  19. else
  20. a = m;
  21. }
  22.  
  23. double pkw = (a + b) / 2.0;
  24.  
  25. cout << pkw << endl;
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
0.5