Program #include<stdio.h> #include<conio.h> int main(void) { int n,i,a[10],p=0,x; clrscr(); printf("Horner's R...
Program
#include<stdio.h>
#include<conio.h>
int main(void)
{
int n,i,a[10],p=0,x;
clrscr();
printf("Horner's Rule\n");
printf("Enter degree of polynomial\n");
scanf("%d",&n);
printf("Enter values for a0, a1, a2, .....\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter value of x: ");
scanf("%d",&x);
for(i=n-1;i>=0;i--)
{
p=p*x+a[i];
printf("%d\n",p);
}
printf("f(x) = %d",p);
getch();
}
Output
#include<stdio.h>
#include<conio.h>
int main(void)
{
int n,i,a[10],p=0,x;
clrscr();
printf("Horner's Rule\n");
printf("Enter degree of polynomial\n");
scanf("%d",&n);
printf("Enter values for a0, a1, a2, .....\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter value of x: ");
scanf("%d",&x);
for(i=n-1;i>=0;i--)
{
p=p*x+a[i];
printf("%d\n",p);
}
printf("f(x) = %d",p);
getch();
}
Output
COMMENTS