fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6. double c = 15.0;
  7. double eps = 0.001;
  8. double x = c; // początkowe przybliżenie
  9.  
  10. while (true) {
  11. double next = 0.5 * (x + c / x);
  12. if (fabs(next - x) < eps)
  13. break;
  14. x = next;
  15. }
  16.  
  17. cout << "Przyblizona wartosc sqrt(" << c << ") = " << x << endl;
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Przyblizona wartosc sqrt(15) = 3.87298