# Horner's Algorithm

• 10-14-2005
swanley007
Horner's Algorithm
Hello,

I am a college student, and I got a question wrong on the last test. I was wondering if anyone could give me the answer, as I am stumped and frustrated.

HERE IT IS:

Horner's Algo can be used to evaluate a polynomial at a point O(n) time.

SEE ATTACHMENT (COULDN"T GET FORMATTING IN THIS WINDOW)
MANY SUPER AND SUBSCRPITS
• 10-14-2005
dwks
Quote:

(COULDN"T GET FORMATTING IN THIS WINDOW)
That's what [code] [/code] tags are for.
• 10-14-2005
dwks
Code:

```double routineC(double coeffs[], int size, double x) {       int I;  // intended to be i?       double y = 0;       for(i=0;i<=size;i++){  // i is undeclared         y += coeffs[i] * pow(x,i);     } }```
• 10-14-2005
rockytriton
might want to return y after the for loop too.
• 10-14-2005
dwks
And come to think of it
Code:

`for(i=0;i<=size;i++){`
you probably want < there, since you're using it to access the array.
• 10-15-2005
swanley007
Tru
You are correct with your changes, sorry I guess I typed too fast...But it still leaves the rest of the problem.
• 10-15-2005
dwks
The rest of the problem? You mean the code that you haven't written yet?
• 10-15-2005
Rashakil Fol
That's not Horner's algorithm. This is.

Code:

```double horners(double * poly, int size, double x) {         double ret = 0.0;         double * end = poly + size;         while (poly != end) {                 ret *= x;                 ret += *poly;                 ++poly;         }         return ret; }```