Write a program in C to evaluate the given polynomial f(x)=a4x 4+a3x 3+a2x 2+a1x+a0 ) for given value of x and the coefficients using Horner’s method.

 Write a program in C to evaluate the given polynomial f(x)=a4x4+a3x3+a2x2+a1x+a0)for given value of x and the coefficients using Horner’s method.

#include<stdio.h>
void main()
{
float a[100], sum=0, x;
int n, i;
printf("Enter the value for n ");
scanf("%d",&n);
printf("Enter %d coefficients into array\n",n);
for(i=n-1; i>=0; i--)
{
scanf("%f",&a[i]);
}
printf("Enter value of x ");
scanf("%f",&x);
for(i=n-1; i>0; i--)
{
sum=(sum+a[i])*x;
}
sum = sum + a[0];
printf("The value of f(%f) = %f",x,sum);
}

Comments