Skip to content
← All examples

Newton's method

C++ Algorithms

loop + update

Flowchart (ISO 5807)

StartInput xg = xi = 0, 19, 1g = (g + x / g) / 2Return gEndFigure 1 — mySqrt

Source code

double mySqrt(double x) {
    double g = x;
    for (int i = 0; i < 20; i++) {
        g = (g + x / g) / 2;
    }
    return g;
}