###### 一元多项式的表示及加减乘除运算

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

typedef struct polyn
{
float coef;
int expn;
struct polyn* next;

#include "test.h"

{
PolyNode *p,*q,*s;
int expn2;
float coef2;
{
return NULL;
}
do
{
printf("输入系数coef(系数和指数都为0结束)");
scanf("%f",&coef2);
printf("输入指数数exp(系数和指数都为0结束)");
scanf("%d",&expn2);
if((long)coef2 == 0 && expn2 == 0)
{
break;
}
if(!s)
{
return NULL;
}
s->expn = expn2;
s->coef = coef2;
while(q && expn2 < q->expn)
{
p = q;
q = q->next ;
}
if(q == NULL || expn2 > q->expn)
{
p->next = s;
s->next = q;
}
else
{
q->coef += coef2;
}
}while(1);
}

{
while(p)
{
printf("%1.1f",p->coef);
if(p->expn)
{
printf("*x^%d",p->expn);
}
if(p->next && p->next->coef > 0)
{
printf("+");
}
p = p->next ;
}
}

{
{
return NULL;
}
L2 = Reverse(L2);
pa = L1->next ;
pb = L2->next ;
while(pa != NULL && pb != NULL)
{
if(pa->expn == pb->expn)
{
if(!u)
{
return NULL;
}
u->coef = pa->coef + pb->coef ;
u->expn = pa->expn ;
pa = pa->next ;
pb = pb->next ;
u->next = pc->next ;
pc->next = u;
pc = u;
}
else if(pa->expn > pb->expn)
{
if(!u)
{
return NULL;
}
u->coef = pa->coef ;
u->expn = pa->expn ;
pa = pa->next ;
u->next = pc->next ;
pc->next = u;
pc = u;
}
else
{
if(!u)
{
return NULL;
}
u->coef = pb->coef ;
u->expn = pb->expn ;
pb = pb->next ;
u->next = pc->next ;
pc->next = u;
pc = u;
}
}
L2 = Reverse(L2);
}

{
{
return NULL;
}
pa = L1->next ;
pb = L2->next ;
while(pa != NULL && pb != NULL)
{
if(pa->expn == pb->expn)
{
if(!u)
{
return NULL;
}
u->coef = pa->coef - pb->coef ;
u->expn = pa->expn ;
pa = pa->next ;
pb = pb->next ;
u->next = pc->next ;
pc->next = u;
pc = u;
}
else if(pa->expn > pb->expn)
{
if(!u)
{
return NULL;
}
u->coef = pa->coef ;
u->expn = pa->expn ;
pa = pa->next ;
u->next = pc->next ;
pc->next = u;
pc = u;
}
else
{
if(!u)
{
return NULL;
}
u->coef = pb->coef ;
u->expn = pb->expn ;
pb = pb->next ;
u->next = pc->next ;
pc->next = u;
pc = u;
}
}
}

{
PolyNode *q,*r,*p = NULL;
while(q)
{
r = q->next ;
q->next = p;
p = q;
q = r;
}
}

{
int k,maxExp;
float coef;
{
return NULL;
}
if(L1->next != NULL && L2->next != NULL)
{
maxExp = L1->next->expn +L2->next->expn ;
}
else
{
}
L2 = Reverse(L2);
for(k = maxExp;k >= 0;k--)
{
pa = L1->next ;
while(pa != NULL && pa->expn > k)
{
pa = pa->next ;
}
pb = L2->next ;
while(pb != NULL && pa != NULL && pa->expn+pb->expn < k)
{
pb= pb->next ;
}
coef = 0.0;
while(pa != NULL && pb != NULL)
{
if(pa->expn +pb->expn == k)
{
coef += pa->coef *pb->coef ;
pa = pa->next ;
pb = pb->next ;
}
else if(pa->expn +pb->expn > k)
{
pa = pa->next ;
}
else
{
pb = pb->next ;
}
}
if(coef != 0.0)
{
u->coef = coef;
u->expn = k;
u->next = pc->next ;
pc->next = u;
pc = u;
}
}
L2 = Reverse(L2);
}

#include "test.h"

int main(void)
{
A = CreatePolyn();
printf("A(x) =");
OutPut(A);
printf("\n");
B = CreatePolyn();
printf("B(x) =");
OutPut(B);
printf("\n");
C = MultiplyPolyn(A,B);
printf("C(x) = A(x)*B(x) =");
OutPut(C);
printf("\n");
printf("D(x) = A(x)+B(x) =");
OutPut(D);
printf("\n");
E = Subtraction(A,B);
printf("E(x) = A(x)-B(x) =");
OutPut(E);
printf("\n");
return 0;
}

#### 一元多项式的建立及其运算

2016-02-05 14:28:10

#### 一元多项式运算器

2016-11-08 22:45:30

#### 5-2 一元多项式的乘法与加法运算 (20分)

2016-08-26 07:44:02

#### 一元多项式的基本运算

2009年05月23日 174KB 下载

#### 数据结构一元多项式运算分析

2014-09-27 22:33:15

#### 【数据结构_链表_List_1040】一元多项式加法运算的实现

2017-03-26 22:58:17

#### 数据结构(3)--线性表实现一元多项式加法

2016-02-05 00:00:38

#### 一元多项式的运算（加、减、乘）C 实现

2011-10-30 09:18:00

#### 单链表模拟一元多项式加减乘运算

2015-03-28 22:30:51

#### 建立与输出一元多项式

2016-10-09 09:42:54