Write a 'C' program to evaluate a given polynomial using function. (Use array).
Answers
Answered by
3
Answer:
void main()
{
int a[10],n,x,i,e;
clrscr();
printf(“\n\nENTER THE DEGREE OF POLYNOMIAL\n\n”);
scanf(“%d”,&n);
printf(“\n\nENTER THE CO-EFFICIENT OF POLYNOMIAL\n\n”);
for(i=n;i>=0;i–)
{
printf(“\n\nCO-EFFICIENT OF A[%d]:-\t “,i);
scanf(“%d”,&a[i]);
}
printf(“\n\nENTERED POLYNOMAIL IS \n\n”);
for(i=n;i>0;i–)
{
if(a[i]!=0)
{
printf(“%dX^%d+”,a[i],i);
}
}
printf(“%d”,a[i]);
printf(“\n\nENTER THE VALUE FOR X”);
scanf(“%d”,&x);
e=eval(a,n,x);
printf(“\nEvaluation of Poly is \t %d”,e);
getch();
}
int eval(int a[],int n,int x)
{
int sum=0,i;
for(i=n;i>=0;i–)
{
sum=sum+a[i]*pow(x,i);
}
return sum;
}
HOPE THIS HELPS YOU
PLEASE MARK MY ANSWER AS BRAINIEST ANSWER
THANK YOU ❤️
Similar questions