Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求救!两个多项式相加和相乘怎么写程序啊?附上相加的程序,求解!

Posted by 1023015455 at 2012-03-15 20:19:52
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator