Computer Science, asked by Samsharma3038, 1 year ago

Write an algorithm to represent a polynomial equation in a linked list

Answers

Answered by prathamesh1855
2
◆Hey There◆


#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(" + ");

          }


}

Similar questions