fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. double pierwiastek (double x, double eps){
  6. double a=0.0;
  7. double b=x;
  8. double c;
  9. while (fabs(b-a)>eps){
  10. c=(a+b)/2;
  11. if(c*c>x)
  12. b=c;
  13. else
  14. a=c;
  15. }
  16. return c;
  17. }
  18. int main() {
  19. cout<< pierwiastek(2,0.0001);
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
1.41425