#include<stdio.h> typedef struct mynode { int coeff,expo; struct mynode *Link; }Node; Node *start=NULL,*start2=NULL; //Display Function void display() { Node *tptr=start; printf("\nPolynomial:\n"); while(tptr) { if(tptr->coeff>0) { if(tptr->expo==1) { printf("%dx+",tptr->coeff); } else if(tptr->expo==0) { printf("%d",tptr->coeff); } else { printf("%dx^%d+",tptr->coeff,tptr->expo); } tptr=tptr->Link; } else { if(tptr->expo==1) { printf("%dx",tptr->coeff); } else if(tptr->expo==0) { printf("%d",tptr->coeff); } else { printf("%dx^%d",tptr->coeff,tptr->expo); } tptr=tptr->Link; } } } //Insertion at the End function void add_node(int v1,int v2) { Node *newp=NULL,*tptr=NULL; newp=(Node*)malloc(sizeof(Node)); newp->coeff=v1; newp->expo=v2; newp->Link=NULL; if(start==NULL) { start=newp; } else { tptr=start; while(tptr->Link!=NULL) { tptr=tptr->Link; } tptr->Link=newp; } } //Main int main() { int v1,v2; char choice; while(v2!=0) { printf("\nEnter the co-eff:"); scanf("%d",&v1); fflush(stdin); printf("\nEnter the expo:"); scanf("%d",&v2); fflush(stdin); add_node(v1,v2); fflush(stdin); } display(); return 0; }
top of page
Search
Recent Posts
See All#include<stdio.h> #include<stdlib.h> int MAX=0;//Max elements in the queue typedef struct mynode { char info; int pri; struct mynode...
bottom of page
Comments