I learned about Horner's Rule here for the first time: Horner's rule in C++ Since I am learning about recursion ATM, I was wondering if it is possible to implement this algorithm using recursion ?
int HornerR( int a[], int n, int x, int index )
{
if (index==n) return a[n];
else
return x*HornerR(a,n ,x,index+1) + a[index];
}
I think it's only possible with a fourth parameter.
You can do it with pointer arithmetic:
Basically this lets you calculate the index variable by moving the array to the next position and sending that (and always using the first cell) instead of sending the whole array every time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With