Anonymous user
Horner's rule for polynomial evaluation: Difference between revisions
Horner's rule for polynomial evaluation (view source)
Revision as of 21:33, 7 November 2010
, 13 years agoAdded C#.
(Pari/GP) |
(Added C#.) |
||
Line 105:
return 0;
}</lang>
=={{header|C sharp|C#}}==
<lang csharp>using System;
using System.Linq;
class Program
{
static double Horner(double[] coefficients, double variable)
{
return coefficients.Reverse().Aggregate((accumulator, coefficient) => accumulator * variable + coefficient);
}
static void Main()
{
Console.WriteLine(Horner(new[] { -19.0, 7.0, -4.0, 6.0 }, 3.0));
}
}</lang>
Output:
<lang>128</lang>
=={{header|C++}}==
The same C function works too, but another solution could be:
|