forked from Arunb-lab1/Hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polynomial_multiplication.c
59 lines (56 loc) · 1.34 KB
/
polynomial_multiplication.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
57
58
59
#include<stdio.h>
#include<stdlib.h>
struct node
{
int coeff;
int power;
struct node *next;
};
void display(struct node* head)
{
while(head->next!=NULL)
{
printf("%dX^%d + ",head->coeff,head->power);
head=head->next;
}
printf("%dX^%d",head->coeff,head->power);
}
void create(struct node ** head)
{
int n;
struct node *temp;
struct node *temp1;
struct node *current;struct node *prev;
printf("Enter the elements to be inserted");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
struct node *newNode = (struct node*)malloc(sizeof(struct node));
printf("Enter value of coefficient and exponent : \n");
scanf("%d%d", &(newNode->coeff), &(newNode->power));
newNode->next=NULL;
temp=*head;
if(*head==NULL || ((*head)->power)>newNode->power)
{
newNode->next=*head;
*head=newNode;
}
else
{
temp=*head;
while( temp->power<newNode->power && temp!=NULL)
{
temp1=temp;
temp=temp->next;
}
newNode->next=temp;
temp1->next=newNode;
}
}
display(*head);
}
void main()
{
struct node *head=NULL;
create(&head);
}