SHARE
TWEET

Untitled

a guest Jan 20th, 2020 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. double sqrt_a(double,  double );
  6.  
  7. int main() {
  8.  
  9.     cout << sqrt_a(3,0.0001);
  10. }
  11.  
  12. double sqrt_a(double a, double eps) {
  13.     double xk = a;
  14.     double xk1 = 0;
  15.    
  16.     while (true) {
  17.         xk1 = (double)(1.0 / 2.0) * (double)(xk + (a / xk));
  18.    
  19.         if (((xk1 - xk) * -1) < eps) {
  20.             break;
  21.         }
  22.  
  23.         xk = xk1;
  24.     }
  25.  
  26.     return xk1;
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top