Write a program to evaluate a polynomial(of single variable X) of degree N for a given value of X
#include<stdio.h>
#include<conio.h>
#include<math.h>
struct polynomial
{
int degree;
int coeff;
};/*End of structure definition*/
void main()
{
struct polynomial poly[10];
int noOfTerms;
int i;
float value=0.0;
int x;
clrscr();
printf("\nEnter Number Of Terms Of The Polynomial: ");
scanf("%d",&noOfTerms);
for(i=0;i<noOfTerms;i++)
{
printf("\nEnter Degree: ");
scanf("%d",&poly[i].degree);
printf("\nEnter Coefficient: ");
scanf("%d",&poly[i].coeff);
}/*End of i for loop*/
printf("\nThe Polynomial You Entered Is: \n");
for(i=0;i<noOfTerms;i++)
{
if(poly[i].degree==0)
printf("%d ",poly[i].coeff);
else if(poly[i].degree==1)
printf("%dx ",poly[i].coeff);
else
{
printf("%dx^%d ",poly[i].coeff,poly[i].degree);
}
if(i!=noOfTerms-1)
printf("+ ");
}/*End of i for loop*/
printf("\nEnter The Value Of X: ");
scanf("%d",&x);
for(i=0;i<noOfTerms;i++)
{
value+=poly[i].coeff * pow(x,poly[i].degree);
}/*End of i for loop*/
printf("\nThe Value Is: %f",value);
getch();
}/*End of main()*/
