![](https://csdnimg.cn/release/download_crawler_static/86849567/bg4.jpg)
}
pa=pa->next;
}
pc->next=NULL;
pa=c;
pc=c->next; // 暂存乘积的第一项地址
for(j=maxe; j>=0; j--) // 合并指数相同的各项
{ p=pc;
m_coef=0.0;
while(p!=NULL)
{ if(p->exp==j) m_coef+=p->coef;
p=p->next;
}
if(fabs(m_coef)>1e-6) // 系数之和非零,建立新的结点存储结果项
{ q=new mulpoly;
q->coef=m_coef; q->exp=j;
pa->next=q; pa=q;
}
}
pa->next=NULL;
while(pc!=NULL) // 释放第一次乘积运算的各项结点
{ p=pc;
pc=pc->next;
delete p; // free(p);
}
return c;
}
void main() // 主函数
{ mulpoly *ha, *hb, *hc, *hd;
cout<<"Input each item of a multipoly:\n";
ha=create();
cout<<"Input each item of another multipoly:\n";
hb=create();
hc=poly_add(ha,hb);
cout<<"The sum of a multipoly: "; output(ha);
cout<<" and another one: "; output(hb);
cout<<" is: "; output(hc);
cout<<endl;
hd=poly_multiply(ha,hb);
cout<<" Their multiply is: "; output(hd);
cout<<endl;
return;
}
3.保存程序项目。