Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double sqrt_a(double a, double eps)
- {
- if (a == 0)
- return 0;
- double x_1 = a;
- double x_next = (x_1 + a / x_1) / 2;
- double x_current = x_1;
- while (abs(x_next - x_current) >= eps)
- {
- x_current = x_next;
- x_next = (x_current + a / x_current) / 2;
- }
- return x_next;
- }
- int main()
- {
- std::cout << std::setprecision(9) << sqrt_a(120.1, 0.000000001) << std::endl;
- std::cout << sqrt(120.1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement