fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. // Stała liczba dodatnia
  8. double A = 10.0;
  9.  
  10. // Przybliżenie początkowe
  11. double x = A;
  12.  
  13. // Dokładność
  14. double eps = 1e-6;
  15.  
  16. // Iteracje Newtona-Raphsona
  17. while (fabs(x * x - A) > eps) {
  18. x = 0.5 * (x + A / x);
  19. }
  20.  
  21. cout << "Przyblizona wartosc sqrt(" << A << ") = " << x << endl;
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Przyblizona wartosc sqrt(10) = 3.16228