Horner's rule for polynomial evaluation: Difference between revisions

Content deleted Content added
No edit summary
Line 976:
 
echo horner([-19, 7, -4, 6], 3)</lang>
 
=={{header|Oberon-2}}==
{{works with|oo2c}}
<lang oberon2>
MODULE HornerRule;
IMPORT
Out;
TYPE
Coefs = POINTER TO ARRAY OF LONGINT;
VAR
coefs: Coefs;
PROCEDURE Eval(coefs: ARRAY OF LONGINT;size,x: LONGINT): LONGINT;
VAR
i,acc: LONGINT;
BEGIN
acc := 0;
FOR i := LEN(coefs) - 1 TO 0 BY -1 DO
acc := acc * x + coefs[i]
END;
RETURN acc
END Eval;
 
BEGIN
NEW(coefs,4);
coefs[0] := -19;
coefs[1] := 7;
coefs[2] := -4;
coefs[3] := 6;
Out.Int(Eval(coefs^,4,3),0);Out.Ln
END HornerRule.
</lang>
{{out}}
<pre>
128
</pre>
=={{header|Objective-C}}==