← All examples

Horner's scheme

C++ Algorithms

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

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;
}