Find the value of the polynomial

Program to find the value of the polynomial f(x)=a4x4+a3x3+a2x2+a1x+a0 using Horner's method
#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();
}

ليست هناك تعليقات:

إرسال تعليق