求c语言一元多项式算法 哪位大哥帮帮忙

来源:百度知道 编辑:UC知道 时间:2024/05/21 14:24:40

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

typedef
struct term
{
short expn; /*幂次*/
double coef; /*系数*/
struct term* next;
}
Term;

/*为了说明问题以下仅演示两个固定多项式
f(x)=3x^3-2x^2+x-1.5
g(x)=4x^4-3x^3+x+0.5
的加法与减法
*/
int main()
{
Term* create(int,double[]);
Term* chains(Term*,Term*,char);
void output(Term*);
void Free(Term*);
double fx[]={ 3,-2,1,-1.5};
double gx[]={4,-3,0,1, 0.5};
Term *hf,*hg,*hsum,*hdif;

/*首先为f(x),g(x)建立链表*/
hf=create(3,fx);
hg=create(4,gx);

/*调用多项式"加法"*/
hsum=chains(hf,hg,'+');
/*遍历hsum输出"和式"*/
output(hsum);
free(hsum);

/*调用多项式"减法"*/
hdif=chains(hf,hg,'-');
/*遍历hdif输出"差式"*/
output(hdif);
free(hdif);

return 0;
}

Te