The results of the program run as follows:
<span style= "font-family:arial, Helvetica, Sans-serif;" ><span style= "FONT-SIZE:18PX;" ># include<stdio.h></span>
# include<stdlib.h>struct Node{int exp;float coef;struct node *next;/* point to struct pointer */};typedef struct node ListNode; ListNode *createpoly ()//create a polynomial linked list {ListNode *h=null,*p,*q=null; int e; float C; printf ("Please enter coefficients and indices:"); scanf ("%f,%d", &c,&e); while (e!=0| | c!=0) {p= (listnode*) malloc (sizeof (ListNode)); p->coef=c; p->exp=e; p->next=null; if (h==null) h=p; else q->next=p; Q=p; printf ("Please enter coefficients and indices:"); scanf ("%f,%d", &c,&e); } return h;} void Disppoly (ListNode *h)/* Output polynomial */{listnode *p;p=h;while (p!=null) {if (p->exp==0) printf ("%.2f", P->coef); elseprintf ("%fx^%d", P->coef,p->exp);p =p->next;if (p!=null) printf ("+");} printf ("\ n"); } ListNode *addpoly (ListNode *h1,listnode *h2)/* Add two polynomial */{ListNode *p,*r=null,*s1,*s2,*s=null; float c; int e; s1=h1; S2=H2; while (S1!=null&&s2!=null) {if (s1->exp==s2->exp) {c=s1->coef+s2->coef; e=s1->exp; s1=s1-> Next s2=s2->next; } else if (s1->exp>s2->exp) {c=s1->coef; E=s1->exp; s1=s1->next; } else {c=s2->coef; e=s2->exp; s2=s2->next;} if (c!=0) {p= (listnode*) malloc (sizeof (ListNode)); p->coef=c; p->exp=e;p->next=null; if (s==null) s=p; else r->next=p; R=p; }} while (S1!=null) {c=s1->coef; e=s1->exp; s1=s1->next; if (c!=0) {p= (listnode*) malloc (sizeof (ListNode)); p-& Gt;coef=c; p->exp=e;p->next=null; if (s==null) s=p; else r->next=p; R=p; }} while (S2!=null) {c=s2->coef; e=s2->exp; s2=s2->next; if (c!=0) {p= (listnode*) malloc (sizeof (ListNode)); p-& Gt;coef=c; p->exp=e;p->next=null; if (s==null) s=p; else r->next=p; R=p; }} return S; } void Deletepoly (ListNode *h)//release polynomial occupies memory unit {listnode *p,*r=h;while (r!=null) {p=r->next;free (r); r=p;}} int main () {ListNode *head1,*head2,*head;printf ("Create first polynomial: \ n"), Head1=createpoly ();p rintf ("Create a second polynomial: \ n"); head2= Createpoly ();p rintf ("add two polynomial: \ n"), Head=addpoly (head1,head2);d Isppoly (head);d Eletepoly (head);} </span>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Two unary polynomial add-ons