| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求救!两个多项式相加和相乘怎么写程序啊?附上相加的程序,求解!#include <stdio.h>
# define maxdegree 5
typedef struct
{
int coeffarray[6];
int highpower;
}*polynomial;
void zeropolynomial(polynomial poly)
{
int i;
for(i=0;i<=maxdegree;i++)
poly->coeffarray[i]=0;
poly->highpower=0;
}
void addpolynomial(const polynomial poly1,const polynomial poly2,polynomial polysum)
{
int i;
zeropolynomial (polysum);
polysum->highpower=max( poly1->highpower,poly2->highpower);
for(i=polysum->highpower;i>=0;i--)
polysum->coeffarray[i]=poly1->coeffarray[i]+poly2->coeffarray[i];
}
int max(int a,int b)
{
if(a>b) return a;
else
return b;
}
void main()
{
polynomial p1,p2,p;
p1->coeffarray[6]={1,0,1,0,1,2};
p2->coeffarray[6]={0,1,2,1,0,1};
printf ("%d\n,"addpolynomial(p1,p2,p));
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator