Skip to content

Horner's scheme

C++ polynomial evaluation

Flowchart (ISO 5807)

StartInput a[], n, xres = a[0]i = 1, n − 1, 1res = res·x + a[i]Return resEndFigure 1 — horner

Source code

C++
double horner(double a[], int n, double x) {
    double res = a[0];
    for (int i = 1; i < n; i++) {
        res = res * x + a[i];
    }
    return res;
}

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

Language
C++
Constructs
polynomial evaluation
Topic
Algorithms
Formats
Word, Visio, draw.io, PDF, SVG

Related examples