-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
77 lines (58 loc) · 1.32 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <stdlib.h>
typedef struct Element
{
int coefficient;
int exponent;
} Element;
typedef struct Term
{
Element element;
struct Term *next;
} Term, *TermPointer;
typedef TermPointer Poly;
void addElementToPoly(Poly poly, int coef, int exp);
Poly createNewPoly();
int main()
{
return 0;
}
void addElementToPoly(Poly poly, int coef, int exp)
{
TermPointer newTerm;
newTerm = (TermPointer)malloc(sizeof(struct Term));
if (newTerm)
{
newTerm->element.coefficient = coef;
newTerm->element.exponent = exp;
TermPointer last;
last = poly;
while (last->next)
{
last = last->next;
}
newTerm->next = last->next;
last->next = newTerm;
}
}
Poly createNewPoly()
{
Poly newPoly;
newPoly = (Poly)malloc(sizeof(struct Term));
int size, coef, exp;
printf("Please enter the size of your poly: ");
scanf("%d", &size);
TermPointer polyHead;
if (newPoly)
{
newPoly->next = NULL;
polyHead = newPoly;
for (int i = 0; i < size; i++)
{
printf("Enter the coefficent and exponent of element %d: ", i+1);
scanf("%d %d", &coef, &exp);
addElementToPoly(polyHead, coef, exp);
}
}
return newPoly;
}