Skip to content

Newton's method

C++ loop + update

Flowchart (ISO 5807)

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

Source code

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

The editor opens with this code — change it and the chart redraws.

Language
C++
Constructs
loop + update
Topic
Algorithms
Formats
Word, Visio, draw.io, PDF, SVG

Related examples