Given the degree of the polynomial and a vector with the polynomial's coefficients is there a more efficient way to recursively calculate the polynomial result for a given x?
This is what i have tried, and it works, but I am asking if there is a more efficient way to do it:
int polynomial(int n,int k,int v[],int x)
{if (k==0){
int s=0;
for(int i=0;i<=n;i++)s+=v[i];
return s;
}
else
{for(int i=0;i<=k-1;i++)v[i]*=x;
polinomyal(n,k-1,v,x);}
}
void main()
{
int n,x,v[10];
printf("n=");
scanf("%i",&n);
for(int i=0;i<=n;i++){
scanf("%i",&(v[i]));
}
printf("x=");
scanf("%i",&x);
printf("rezultatul este: %i",polynomial(n,n,v,x));
}
I have tried to find a formula to determine S(n+1) from S(n) and x but have not found anything that way.