-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15_polyrep.c
58 lines (55 loc) · 962 Bytes
/
15_polyrep.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
//Govind J Nair
//S3-D
//23
#include<stdio.h>
#include<stdlib.h>
struct node
{
int exp,coef;
struct node *link;
};
void main()
{
struct node *temp,*head,*ptr;
int ex,coe,c;
temp=(struct node*)malloc(sizeof(struct node));
temp->exp=0;
temp->coef=0;
temp->link=NULL;
ptr=head;
do
{
printf("Enter coefficient: ");
scanf("%d",&coe);
if(coe==0)
{
printf("\n");
}
else
{
printf("Enter exponent: ");
scanf("%d",&ex);
temp=(struct node*)malloc(sizeof(struct node));
temp->exp=ex;
temp->coef=coe;
temp->link=NULL;
ptr->link=temp;
ptr=ptr->link;
}
printf("1. Add more elements\n2. Continue\nEnter choice: ");
scanf("%d",&c);
}while(c==1);
printf("1. Display polynomial\n2. Exit\nEnter choice: ");
scanf("%d",&c);
if(c==1)
{
ptr=head->link;
printf("F(p) = ");
while(ptr!=NULL)
{
printf("%d p^%d + ",ptr->coef,ptr->exp);
ptr=ptr->link;
}
printf("0\n");
}
}