forked from oops-aman/Data-Structures-in-C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Polynomials_using_Linked_List.c
56 lines (51 loc) · 1.09 KB
/
Polynomials_using_Linked_List.c
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
#include<stdio.h>
#include<stdlib.h>
struct poly
{
int coeff,pow;
struct poly *next;
}*t1,*t2;
void create()
{
int flag=1;
t1=(struct poly*)malloc(sizeof(struct poly*));
do
{
printf("Enter coefficient : ");
scanf("%d",&t1->coeff);
printf("Enter power : ");
scanf("%d",&t1->pow);
printf("Want to insert more terms (1-Yes/0-No) : ");
scanf("%d",&flag);
if(flag==1)
{
t1->next=(struct poly*)malloc(sizeof(struct poly*));
t1=t1->next;
t1->next=0;
}
}while(flag==1);
}
void display(struct poly *head)
{
t2=head;
printf("%dx^%d",t2->coeff,t2->pow);
t2=t2->next;
if(t2!=0)
{
printf(" + ");
display(t2);
}
}
int main()
{
struct poly *poly1,*poly2;
printf("First Polynomial : \n");
create(&poly1);
printf("\nSecond Polynomial : \n");
create(&poly2);
printf("\n\nPolynomial 1 : ");
display(poly1);
printf("\nPolynomial 2 : ");
display(poly2);
return 0;
}