资源描述
#define LEN sizeof(node)/结点构造typedef struct polynodeint coef;/系数指数int exp;/struct polynode*next;node;node*create(void)node*h,*r,*s;int c,e;h=(node*)malloc(LEN);r=h;printf(系数:);scanf(%d,&c);printf(指数:);scanf(%d,&e);while(c!=0)s=(node*)malloc(LEN);s-coef=c;s-exp=e;r-next=s;r=s;printf(系数:);scanf(%d,&c);printf(指数:);scanf(%d,&e);r-next=NULL;return(h);void polyadd(node*polya,node*polyb)node*p,*q,*pre,*temp;int sum;p=polya-next;q=polyb-next;pre=polya;while(p!=NULL&q!=NULL)if(p-expq-exp)pre-next=p;pre=pre-next;p=p-next;else if(p-exp=q-exp)sum=p-coef+q-coef;if(sum!=0)p-coef=sum;pre-next=p;pre=pre-next;p=p-next;temp=q;q=q-next;free(temp);elsetemp=p-next;free(p);p=temp;temp=q-next;free(q);q=temp;elsepre-next=q;pre=pre-next;q=q-next;if(p!=NULL)pre-next=p;elsepre-next=q;void print(node*p)while(p-next!=NULL)p=p-next;printf(”d*xA%d,p-coef,p-exp);void main()node*polya,*polyb;printf(请输入第一个多项式的系数和指数n(输入系数为0时,表示多项式的输入结 束):n);polya=create();printf(多项式为:);print(polya);printf(nn请输入第二个多项式的系数和指数n(输入系数为0时,表示多项式的输 入结束):n);polyb=create();printf(多项式为:);print(polyb);printf(nn多项式和为:);polyadd(polya,polyb);print(polya);printf(n);getchar();
展开阅读全文