"Fatal.h"//header file
1 #include <stdio.h>2 #include <stdlib.h>3#define Error (STR) FatalError (str)4#define fatalerror (str) fprintf (stderr, "%s\n", Str), exit (1);
1 /*This code doesn ' t really do much*/2 /*Thus I Haven ' t bothered testing it*/3 4#include"fatal.h"//header file5 6 #defineMaxdegree 100//defined polynomial maximum exponent is 1007 8 Static int9Max (intAintB)Ten { One returnA > B?a:b;//returns the maximum value in AB A } -Define a struct array thetypedefstruct - { - intcoeffarray[Maxdegree +1];//need to store more than one constant entry - inthighpower;//the highest index of the stored polynomial +} *polynomial; - /*END*/ + A /*START:fig3_19.txt*/ at void - zeropolynomial (polynomial Poly)//Initialize polynomial - { - inti; - - for(i =0; I <= Maxdegree; i++ ) inpoly->coeffarray[I] =0; -Poly->highpower =0; to } + /*END*/ - the /*START:fig3_20.txt*/ * void//Two polynomial add-ons $Addpolynomial (ConstPolynomial Poly1,Constpolynomial Poly2,Panax Notoginseng polynomial polysum) - { the inti; + A zeropolynomial (polysum); thePolysum->highpower = Max (poly1->Highpower, +Poly2->highpower); - $ for(i = polysum->highpower; i >=0; i-- ) $polysum->coeffarray[i] = poly1->coeffarray[i] -+ poly2->coeffarray[i]; - } the /*END*/ - Wuyi /*START:fig3_21.txt*/ the void//two polynomial multiplication -Multpolynomial (Constpolynomial Poly1, Wu Constpolynomial Poly2, polynomial polyprod) - { About intI, J; $ - zeropolynomial (Polyprod); -Polyprod->highpower = Poly1->highpower + poly2->Highpower; - A if(Polyprod->highpower >maxdegree) +Error ("exceeded array size" ); the Else - for(i =0; I <= poly1->highpower; i++ ) $ for(j =0; J <= poly2->highpower; J + + ) thepolyprod->coeffarray[i + j] + = thepoly1->coeffarray[i] * thePoly2->coeffarray[J]; the } - /*END*/
Adding and subtraction multiplication of polynomial by array