arsovski

sqrt_a

Feb 6th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.25 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. double sqrt_a(double a, double eps) {
  4.     int xk[100];
  5.     xk[1] = a;
  6.     int  i = 2;
  7.     for (; abs(xk[i] - xk[i - 1]) < eps; i++)
  8.     {
  9.         xk[i] = 1 / 2 * (xk[i - 1] + (a / xk[i - 1]));
  10.     }
  11.     return abs(xk[i] - xk[i - 1]);
  12. }
Advertisement
Add Comment
Please, Sign In to add comment