-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPOLYLIN1.C
50 lines (47 loc) · 1 KB
/
POLYLIN1.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
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
typedef struct node* polynomial;
struct node
{
int coef,exp;
polynomial next;
};
void main()
{
polynomial p,t;
int i,n;
clrscr();
printf("Number of terms in the polynomial : ");
scanf("%d",&n);
printf("\nEnter %d terms for the polynomial:\n",n);
p=(polynomial)malloc(sizeof(*p));
printf("\nCoefficient : ");
scanf("%d",&p->coef);
printf("Exponent : ");
scanf("%d",&p->exp);
p->next=NULL;
t=p;
for(i=0;i<n-1;i++)
{
t->next=(polynomial)malloc(sizeof(*p));
t=t->next;
printf("\nCoefficient : ");
scanf("%d",&t->coef);
printf("Exponent : ");
scanf("%d",&t->exp);
t->next=NULL;
}
printf("\nThe polynomial : ");
if(p->exp==0) printf("%d",p->coef);
else if(p->exp==1) printf("%dx",p->coef);
else printf("%dx^%d",p->coef,p->exp);
for(t=p->next;t!=NULL;t=t->next)
{
if(t->coef>0) printf("+");
if(t->exp==0) printf("%d",t->coef);
else if(t->exp==1) printf("%dx",t->coef);
else printf("%dx^%d",t->coef,t->exp);
}
getch();
}