Program
: Create Polynomial equation using
Linked List
Polynomial
equation
5x^3
+4x^2+6x^1
// Create polynomial equation
using linked list
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct link
{
int
coef;
int
exp;
struct
link *next;
};
struct link *node,*start;
int i;
void create_poly(struct link
*node);
void display(struct link *node);
void main()
{
clrscr();
printf("\n
create polynomial equation");
node=(struct
link *)malloc(sizeof(struct link));
create_poly(node);
printf("\n
Output\n");
display(node);
getch();
}
void create_poly(struct link
*node)
{
char
ans;
i=0;
start->next=NULL;
node=start;
fflush(stdin);
printf("\n
Enter 'n' for break:-");
ans=getchar();
while(ans!='n')
{
node->next=(struct
link *)malloc(sizeof(struct link));
node=node->next;
printf("\n
Enter Coeficient value : ");
scanf("%d",&node->coef);
printf("\n
Enter exponent value : ");
scanf("%d",&node->exp);
node->next=NULL;
fflush(stdin);
printf("\n
Enter 'n' for break:-");
ans=getchar();
i++;
}
}
void display(struct link *node)
{
node=start->next;
while(node)
{
printf("%dX
^ %d",node->coef,node->exp);
node=node->next;
if(node!=NULL)
printf(" + ");
}
}
Posted By : Ruchita Pandya