Program to find the value of the polynomial f(x)=a4x4+a3x3+a2x2+a1x+a0 using Horner’s method

Here is the program to find the value of the polynomial f(x)=a4x^4+a3x^3+a2x^2+a1^x+a0 using Horner’s method

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "stdio.h"
#include "conio.h"
void main()
{
 float a[100],sum=0,x;
 int n,i;
 clrscr();
 printf("Enter the degree of the polynomial:");
 scanf("%d",&n);
 printf("Enter the coefficients into the array:");
 for(i=n;i>=0;i--)
 {
  scanf("%f",&a[i]);
 }
 printf("Enter the value of x:");
 scanf("%f",&x);
 for(i=n;i>0;i--)
 {
  sum=(sum+a[i])*x;
 }
 sum=sum+a[0];
 printf("\nValue of the polynomial is =%f",sum);
 getch();
}

Consider the polynomial 3x^4+2x^3+x^2+x+2 where x=2, then the output will be as follows,
Output:

Enter the degree of the polynomial:
4
Enter the coefficients into the array:
3
2
1
1
2
Enter the value of x:
2
Value of the polynomial is:72.000000

6 Responses to “Program to find the value of the polynomial f(x)=a4x4+a3x3+a2x2+a1x+a0 using Horner’s method”

  1. I can’t understand the 21st line … Can anyone explain that line meaning ?

    Reply
    • Sreenath M

      We need to add the constant term A0, so once we come out of the loop… We need to add it separately…

      Reply
  2. Hi there I am so glad I found your web site, I really found
    you by mistake, while I was searching on Yahoo for something else, Anyhow
    I am here now and would just like to say cheers for a marvelous post and a all round interesting blog (I also love the theme/design), I don’t have
    time to go through it all at the minute but I have book-marked it and also added in your RSS feeds, so
    when I have time I will be back to read much more, Please do keep
    up the fantastic jo.

    Reply

Leave a Reply