## Design & Develop and Implement a Program in C for evaluate a Polynomial

In the circular linked list the last node of the list contains the address of the first node and forms a circular chain.A polynomial equation is an equation that can be written in the form. axn + bxn-1 + . . . + rx + s = 0, where a, b, . . . , r and s are constants. We call the largest exponent of x appearing in a nonzero
term of a polynomial the degree of that polynomial. As with polynomials with one variable, you must pay attention to the rules of exponents and the order of operations so that you correctly evaluate an expression with two or more variables.

Evaluate x2 + 3y3for x = 7 and y = −2. Substitute the given values for x and y.

Evaluate 4x2y – 2xy2 + x – 7 for x = 3 and y = −1.

When a term contains both a number and a variable part, the number part is called the “coefficient”. The coefficient on the leading term is called the “leading” coefficient.

Steps required for Evaluating Polynomial Functions:
Step 1: Replace each x in the expression with the given value.
Step 2: Use the order of operation to simplify the expression

Steps required for addition of two polynomials.
Step 1
 Arrange the Polynomial in standard form
 Standard form of a polynomial just means that the term with highest degree is first and each of the following terms
Step 2
 Arrange the like terms in columns and add the like terms

				
#include<stdio.h>
#include<alloc.h>
#include<math.h>
struct node
{
int cf, px, py, pz; int flag;
};
typedef struct node NODE;
NODE* getnode()
{
NODE *x;
x=(NODE*)malloc(sizeof(NODE));
if(x==NULL)
{
printf("Insufficient memory\n"); exit(0);
}
return x;
}
{
NODE *temp;
{
printf("Polynomial does not exist\n"); return;
}
printf("\n");

{
printf("%d x^%d y^%d z^%d",temp->cf,temp->px,temp->py,temp->pz);
printf(" + ");
}
printf("\n");
}
NODE* insert_rear(int cf,int x,int y,int z,NODE *head)
{
NODE *temp,*cur;
temp=getnode();
temp->cf=cf;
temp->px=x;
temp->py=y;
temp->pz=z;
{
}
}
{
int px, py, pz, cf, ch;
printf("\nEnter coeff: ");
scanf("%d",&cf);
printf("\nEnter x, y, z powers(0-indiacate NO term): ");
scanf("%d%d%d", &px, &py, &pz);
printf("\nIf you wish to continue press 1 otherwise 0: ");
scanf("%d", &ch);
while(ch != 0)
{

printf("\nEnter coeff: ");
scanf("%d",&cf);
printf("\nEnter x, y, z powers(0-indiacate NO term): "); scanf("%d%d%d",
printf("\nIf you wish to continue press 1 otherwise 0: "); scanf("%d", &ch);
}
}
{
NODE *p1,*p2;
int x1,x2,y1,y2,z1,z2,cf1,cf2,cf;
while(p1!=h1)
{
x1=p1->px;
y1=p1->py;
z1=p1->pz;
cf1=p1->cf;
while(p2!=h2)
{
x2=p2->px;
y2=p2->py;
z2=p2->pz;
cf2=p2->cf;
if(x1==x2 && y1==y2 && z1==z2)
break;
}
if(p2!=h2)
{
cf=cf1+cf2;
p2->flag=1;
if(cf!=0)
h3=insert_rear(cf,x1,y1,z1,h3);
}
else
h3=insert_rear(cf1,x1,y1,z1,h3);

}
while(p2!=h2)
{
if(p2->flag==0)
h3=insert_rear(p2->cf,p2->px,p2->py,p2->pz,h3);
}
return h3;
}
void evaluate(NODE *h1)
{
x, y, z;
float result=0.0;
printf("\nEnter x, y, z, terms to evaluate:\n");
scanf("%d%d%d", &x, &y, &z);
{
result = result + (h1->cf * pow(x,h1->px) * pow(y,h1->py) * pow(z,h1->pz));
}
result = result + (h1->cf * pow(x,h1->px) * pow(y,h1->py) * pow(z,h1->pz));
printf("\nPolynomial result is: %f", result);
}
void main() {
NODE *h1,*h2,*h3; int
ch; clrscr();
h1=getnode();
h2=getnode();
h3=getnode();
while(1)
{

scanf("%d", &ch);
switch(ch)
{
case 1:
printf("\nEnter polynomial to evaluate:\n");
display(h1);
evaluate(h1);
break;
case 2:
printf("\nEnter the first polynomial:");
printf("\nEnter the second polynomial:");
printf("\nFirst polynomial is: ");
display(h1);
printf("\nSecond polynomial is: ");
display(h2);
printf("\nThe sum of 2 polynomials is: ");
display(h3);
break;
case 3:
exit(0); break;
default:
printf("\nInvalid entry"); break;
} getch();
}
}


OUTPUT:
1. Evaluate polynomial P(x,y,z) = 6x2y2z-4yz5+3x3yz+2xy5z-2xyz3

3. Exit
Enter polynomial to
evaluate: Enter coeff:
6

Enter x, y, z powers (0-indiacate NO term:
2 2 1
If you wish to continue press 1 otherwise 0:
1 Enter coeff: -4
Enter x, y, z powers (0-indiacate NO term: 0
1 5
If you wish to continue press 1 otherwise 0:
1
Enter coeff: 3
Enter x, y, z powers (0-indiacate NO term: 3 1 1
If you wish to continue press 1
otherwise 0: 1
Enter coeff: 2
Enter x, y, z powers (0-indiacate NO term: 1 5 1
If you wish to continue press 1
otherwise 0: 1
Enter coeff: -2
Enter x, y, z powers (0-indiacate NO term: 1 1 3
If you wish to continue press 1 otherwise 0: 0
Polynomial is:
6 x^2 y^2 z^1 + -4 x^0 y^1 z^5 + 3 x^3 y^1 z^1 + 2 x^1 y^5 z^1 + -2 x^1 y^1 z^3
Enter x, y, z, terms to
evaluate: 1 1 1
Polynomial result is: 5.000000
1. Evaluate polynomial P(x,y,z) = 6x2y2z-
3. Exit

Enter your choice: 2
Enter 1st polynomial:
Enter coeff: 4
Enter x, y, z powers (0-indiacate NO term: 2 2 2
If you wish to continue press 1
otherwise 0: 1 Enter coeff: 3
Enter x, y, z powers (0-indiacate NO term: 1 1 2
If you wish to continue press 1 otherwise 0: 0
Enter 2nd polynomial:
Enter coeff: 6

Enter x, y, z powers (0-indiacate NO term:
2 2 2
If you wish to continue press 1 otherwise 0:
0
Polynomial is:
1st Polynomial is:
4 x^2 y^2 z^2 + 3 x^1 y^1 z^2
2nd Polynomial
is: 6 x^2 y^2
z^2
Added polynomial: 10 x^2 y^2 z^2 + 3 x^1 y^1 z^2
1. Evaluate polynomial P(x,y,z) = 6x2y2z-
Enter your choice: 3