printf("%dx^%d",p->coef,p->exp);
}
p=p->next;
}
(4)一元多项式的加法运算
pnode * add(pnode *heada,pnode *headb)
{ p=heada; q=headb;
headc=(pnode *)malloc(sizeof(pnode));
r=headc;
while(p!=NULL&&q!=NULL)
{if(p->exp==q->exp)
{x=p->coef+q->coef;;
if(x!=0)
{s=(pnode *)malloc(sizeof(pnode));
s->coef=x;
s->exp=p->exp;
r->next=s;
r=s;
}
q=q->next;p=p->next;
}
s->exp=q->exp;
r->next=s;
r=s;
q=q->next;
}
else
{s=(pnode *)malloc(sizeof(pnode));
s->coef=p->coef;
s->exp=p->exp;
r->next=s;
r=s;
p=p->next;
}
}
while(p!=NULL)
{s=(pnode *)malloc(sizeof(pnode));
s->coef=p->coef;
s->exp=p->exp;
r->next=s;
r=s;
需要完整内容的请联系QQ752018766,本文免费,转发请注明源于www.youerw.com
q=q->next;
}
r->next=NULL;
headc=headc->next;
return headc;
(5)一元多项式减法
pnode * sub(pnode *heada,pnode *headb)
{
p=heada;q=headb;
headc=(pnode *)malloc(sizeof(pnode));
r=headc;
while(p!=NULL&&q!=NULL)
{if(p->exp==q->exp)
{x=p->coef-q->coef;
if(x!=0)
{s=(pnode *)malloc(sizeof(pnode));
s->coef=x;
s->exp=p->exp;
r->next=s;
r=s;
}
q=q->next;p=p->next;
}
else if(p->exp<q->exp)
{s=(pnode *)malloc(sizeof(pnode));
s->coef=-q->coef;
s->exp=q->exp;
r->next=s;
r=s;
q=q->next;
}
else
{s=(pnode *)malloc(sizeof(pnode));
s->coef=p->coef;
s->exp=p->exp;
r->next=s;
r=s;
p=p->next;
}
}
while(p!=NULL)
{s=(pnode *)malloc(sizeof(pnode));
s->coef=p->coef;
s->exp=p->exp;
r->next=s;
s->coef=-q->coef;
s->exp=q->exp;
r->next=s;
r=s;
q=q->next;
}
r->next=NULL;
headc=headc->next;
return headc
上一页 [1] [2] [3] [4] [5] [6] [7] 下一页