Horner's rule for polynomial evaluation: Difference between revisions
Horner's rule for polynomial evaluation (view source)
Revision as of 17:27, 23 April 2023
, 1 year agoAdded Gambas
(Added various dialects BASIC (Applesoft BASIC, BASIC256, Chipmunk Basic, GW-BASIC, Minimal BASIC, MSX Basic, QBasic, Quite BASIC and Yabasic)) |
(Added Gambas) |
||
Line 352:
<pre>Horner's algorithm for the polynomial
6*x^3 - 4*x^2 + 7*x - 19 when x = 3 is: 128</pre>
==={{header|Gambas}}===
<syntaxhighlight lang="vbnet">Public coeficientes As New Integer[4]
Public Function AlgoritmoHorner(coeficientes As Integer[], x As Integer) As Integer
coeficientes[0] = -19
coeficientes[1] = 7
coeficientes[2] = -4
coeficientes[3] = 6
Dim i As Integer, acumulador As Integer = 0
For i = coeficientes.Count - 1 To 0 Step -1
acumulador = (acumulador * x) + coeficientes[i]
Next
Return acumulador
End Function
Public Sub Main()
Dim x As Integer = 3
Print "Horner's algorithm for the polynomial 6*x^3 - 4*x^2 + 7*x - 19 when x = 3: ";
Print AlgoritmoHorner(coeficientes, x)
End </syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|GW-BASIC}}===
|