#ifndef QUANTIC_H
#define QUANTIC_H
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include "malloc.h"
typedef struct Quantic
{
double factor;//系数
int order; //阶数
struct Quantic *next;
}Quantic;
Quantic *CreateList(int num) //创建多项式
{
Quantic *head1,*head2,*rear1,*rear2,*p;
double a[3]={1,2,3};
int b[3]={0,1,2};
if(num==1)
{
head1=NULL;
for(int i=0;i<3;i++)
{
p=(Quantic *)malloc(sizeof(Quantic));
p->factor=a[i];p->order=b[i];
if(head1==NULL) head1=p;
else rear1->next=p;
rear1=p;
}
rear1->next=NULL;
return head1;
}
else if(num==2)
{
head2=NULL;
for(int i=0;i<3;i++)
{
p=(Quantic *)malloc(sizeof(Quantic));
p->factor=a[i]+1;p->order=b[i]+1;
if(head2==NULL) head2=p;
else rear2->next=p;
rear2=p;
}
rear2->next=NULL;
return head2;
}
}
void PrintList(Quantic *head) //打印多项式
{
Quantic *p=head;
printf("\nf(x)=");
while(p!=NULL)
{
if(p->factor!=0)
{
printf("(%.3f)*x(%d)+",p->factor,p->order);
}
p=p->next;
}
printf("\n");
}
Quantic *SumList(Quantic *head1,Quantic *head2,int mark) //对两个多项式求和
{
Quantic *p1=head1,*p2=head2;
Quantic *p,*head,*rear;
head=NULL;
while(p1 && p2) //head1和head2都不为空
{
p=(Quantic *)malloc(sizeof(Quantic));
if(p1->order > p2->order)
{
p=p2;
if(m

本文档介绍如何使用C语言来实现对多项式的操作。涵盖了多项式的基本运算,如加法、减法、乘法等。
最低0.47元/天 解锁文章
5648

被折叠的 条评论
为什么被折叠?



