Horner rule in C ++

When trying to redeem polynomials using the Horner Rule, I have an example code segment, for example:

int Horner( int a[], int n, int x )
{
    int result = a[n];
    for(int i=n-1; i >= 0 ; --i)
        result = result * x + a[i];
    return result;
}

I understand that ais an array of coefficients and that xis a value that I would like to evaluate in. My question is: what is it for n?

+3
source share
5 answers

n is the degree of the polynomial (and a polynomial of degree n, except 0, which is special, has n + 1 coefficients, so the size of the array = n + 1, n = the size of the array - 1)

+9
source

n - array size

+4
source

'n' - . , n , .

+2

. :

int result = a[n];

, n - ... n - 1, , . , .

+2

++ . - , . n Horner, .

++ , . 0, - arr[n-1].

0

Source: https://habr.com/ru/post/1722273/


All Articles