-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathploynomial_3.c
More file actions
116 lines (108 loc) · 2.49 KB
/
Copy pathploynomial_3.c
File metadata and controls
116 lines (108 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
typedef struct polynomial
{
float coef;
int exp_x,exp_y,exp_z;
struct polynomail *link;
}poly;
poly *getnode();
void read_poly(poly *,int);
void print_poly(poly *);
void evaluate(poly *);
poly* add_poly(poly*,poly*);
int COMP(poly*,poly*);
int main()
{
int n1,n2;
poly *head1=getnode();
poly *head2=getnode();
poly *head3=getnode();
head1->link=head1;
head2->link=head2;
head3->link=head3;
printf("Enter the number of terms in first polynomial: ");
scanf("%d",&n1);
printf("Enter the number of terms in second polynomial: ");
scanf("%d",&n2);
printf("Reading 1st polynomial \n");
read_poly(head1,n1);
printf("Reading 2nd polynomial \n");
read_poly(head2,n2);
printf("The first polynomial is : ");
print_poly(head1);
printf("The second polynomial is : ");
print_poly(head2);
head3=add_poly(head1,head2);
printf("The sum of the two polynomials is : ");
print_poly(head3);
//Evaluation of polynomial(Substituting x y z values in any polynomial)
evaluate(head1);
// evaluate(head2);
// evaluate(head3);
}
poly *getnode()
{
poly* temp=(poly *)malloc(sizeof(poly));
return temp;
}
void read_poly(poly *head,int n)
{
poly *new,*temp;
temp=head;
for(int i=0;i<n;i++)
{
new=getnode();
printf("Enter the coef x y z values : ");
scanf("%f %d %d %d",&new->coef,&new->exp_x,&new->exp_y,&new->exp_z);
temp->link=new;
temp=temp->link;
}
temp->link=head;
}
void print_poly(poly *head)
{
poly *temp;
temp=head->link;
while(temp!=head)
{
printf("%f x^%d y^%d z^%d + ",temp->coef,temp->exp_x,temp->exp_y,temp->exp_z);
temp=temp->link;
}
}
int COMP(poly *h1,poly *h2)
{
if(h1->exp_x==h2->exp_y && h2->exp_y==h2->exp_y && h1->exp_z==h2->exp_z)
return 1;
return 0;
}
poly* add_poly(poly* h1,poly* h2)
{
poly*temp1=h1->link;
poly*temp2;
poly*result=getnode();
poly* tempres=result;
while(temp1!=h1)
{
temp2=h2->link;
while(temp2!=h2)
{
switch(COMP(temp1,temp2))
{
case 1:
}
}
}
}
void evaluate(poly *head)
{
poly *temp=head->link;
double x,y,z,sum=0.0,tx,ty,tz;
printf("enter the values for x y z");
scanf("%f %f %f",&x,&y,&z);
while(temp!=head)
{
tx=(double)temp->exp_x;
ty=(double)temp->exp_y;
tz=(double)temp->exp_z;
//incomplete
}
}