Advertisement
STANAANDREY

sqrt

Feb 1st, 2020
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. double mysqrt(double x)
  2. {
  3.     double l = 0, r = x, mid;
  4.     for (int i = 0; i < 1e3; i++)
  5.     {
  6.         mid = (l + r) / 2;
  7.         if (mid * mid == x)
  8.             return mid;
  9.         else if (mid * mid > x)
  10.             r = mid;
  11.         else
  12.             l = mid;
  13.     }
  14.  
  15.     return mid;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement