Horner scheme

Let p[0…n] be a vector of integer numbers that contains the coefficients
of a polynomial of degree n ≥ 0. For instance, the vector
p = ⟨3, 2, 5, −1⟩ represents p(x) = 3 + 2x + 5x² − x³, a polynomial of
degree n = 3.

Write a function

        int evaluate(const vector<int>& p, int x);

that evaluates the polynomial at the point @x@, that is, that returns
$\sum_{i=0}^n p[i]x^i$.

Use the Horner scheme:
p_(n)x^(n) + p_(n − 1)x^(n − 1) + … + p₀ = ((p_(n)x + p_(n − 1))x + …)x + p₀.

Observation

You only need to submit the required procedure; your main program will
be ignored.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:01:05.234Z

© Jutge.org, 2006–2026.
https://jutge.org
