Write an algorithm which will evaluate Pn (x) = (N + 1)xn + N x n - 1 + ... + 2x + 1

i am trying to write an algorithm which will evaluate:

Pn(x) = (N + 1)xn + N xn - 1 + ... + 2x + 1

So far I have this, but my professor says that the I+1 is wrong. I am unsure why, can anyone explain or give any suggestions. Thank you

[code]
SUM:=0
POWER:=1
i:=0
WHILE(I<N)
BEGIN
SUM:= SUM + (I+1) * POWER
POWER:= POWER*X
I:= I+1
END

Last edited on
Except for your termination condition, your algorithm is correct.

I suspect your professor looked at I and N and made a quick (and mistaken) judgement.

Just watch the off-by-one error on line 4.
Topic archived. No new replies allowed.