#include<stdio.h>
#include<conio.h>
#include<math.h>
typedef struct
{
int coeff,pw;
}polyno;
void read(polyno p[],int n);
void print(polyno p[], int n);
int eval(polyno p[], int n, int x);
void main()
{
int n1,x;
polyno p1[10];
printf("\nEnter the number of terms in polynomial: ");
scanf("%d",&n1);
printf("\nEnter polynomial: ");
read(p1,n1);
printf("\nFirst polynomial is: ");
print(p1,n1);
printf("\nEnter the value of x: ");
scanf("%d",&x);
printf("\nValue of first polynomial is: %d ",eval(p1,n1,x));
getch();
}
void read(polyno p[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("\nEnter the coefficient of term %d: ",i+1);
scanf("%d",&p[i].coeff);
printf("\nEnter power of term %d: ",i+1);
scanf("%d",&p[i].pw);
}
}
void print(polyno p[], int n)
{
int i;
for(i=0;i<n-1;i++)
{
printf("%d[x]^%d+",p[i].coeff,p[i].pw);
}
printf("%d[x]^%d",p[i].coeff,p[i].pw);
}
int eval(polyno p[], int n, int x)
{
int s=0,i;
for(i=0;i<n;i++)
{
s=s+p[i].coeff*pow(x,p[i].pw);
}
return s;
}
Ads
Pages
ABOUT BLOG
EASY TO CODE
Welcome to Easy to Code, your number one source for all programs.Coding is used for communicating with computers so we're dedicated to providing you the very best solutions. We hope you enjoy our programs as much as we enjoy offering them to you. If you have any questions or comments, please don't hesitate to contact us.
POPULAR POSTS
Translate
Slider
5/random/slider
Advertisement
Tags
Recent in Recipes
3/Food/post-list
0 Comments