#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void accept_poly(int b[], int m)
{
int i;
for(i=m-1; i>=0; i--)
{
printf("Enter coefficent of x[%d] term: ",i);
scanf("%d",&b[i]);
}
}
void disp_poly(int b[], int n)
{
int i;
for(i=n-1; i>=0; i--)
{
if(b[i]>0)
printf("+%dx^%d",b[i],i);
else if(b[i]<0)
printf("%dx^%d",b[i],i);
}
printf("\n");
}
int eval(int b[], int n, int x)
{
int i,ans=0;
for(i=n-1;i>=0;i--)
ans = ans + b[i] * pow(x,i);
return ans;
}
void main()
{
int a[10],n,x;
clrscr();
printf("Enter order of polynomial: ");
scanf("%d",&n);
accept_poly(a,n);
printf("Entered polynomial: ");
disp_poly(a,n);
printf("Enter Value of x: ");
scanf("%d",&x);
printf("Evaluated Value: %d",eval(a,n,x));
getch();
}
Output:
Enter order of polynomial: 2
Enter coefficent of x[1] term: 3
Enter coefficent of x[0] term: 2
Entered polynomial: +3x^1+2x^0
Enter Value of x: 2
Evaluated Value: 8
/
Recent Posts
Posted on 2019-07-18
Posted on 2019-07-18
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-05-28
Posted on 2019-05-24
Posted on 2019-05-24
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23