forked from AugustineAykara/Data-Structure-In-C
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolynomialCreate.c
More file actions
77 lines (61 loc) · 1004 Bytes
/
polynomialCreate.c
File metadata and controls
77 lines (61 loc) · 1004 Bytes
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
#include <stdio.h>
#include <stdlib.h>
struct node
{
int c;
int e;
struct node *addr;
}*head = NULL;
void traversal(struct node *h)
{
struct node *ptr;
ptr = h;
while(ptr != NULL)
{
printf(" %dx^%d +", ptr -> c, ptr -> e);
ptr = ptr-> addr;
}
printf("\n\n");
}
struct node * createNode(int coeff, int exp)
{
struct node *nd;
nd = (struct node *) malloc (sizeof(struct node));
nd -> c = coeff;
nd -> e = exp;
nd -> addr = NULL;
return nd;
}
void createPoly(int n)
{
int coeff, exp;
struct node *ptr, *nd;
// head = createNode(0,0);
for (int i = 0; i < n; ++i)
{
printf("\n Enter the coefficient : ");
scanf("%d", &coeff);
printf(" Enter the exponent : ");
scanf("%d", &exp);
nd = createNode(coeff, exp);
if (head == NULL)
{
head = nd;
ptr = nd;
}
else
{
ptr -> addr = nd;
ptr = nd;
}
}
printf("\n");
traversal(head);
}
void main()
{
int n;
printf("\n Enter the size of polynomial : ");
scanf("%d", &n);
createPoly(n);
}