Note: polyadd procedure is available in previous post.
Procedure for polynomial multiplication
Vector = array[1 .. 40] of integer;
Procedure AddPolynomial(A,B,C : Vector)
i, j: Integer;
D: Vector;
begin
C[1]=1; C[2]= -maxint; C[3]=-maxint;
D[1]=1; i=2; j=2;
while (i<= 2*A[i])
begin
while (j<= 2*B[j])
begin
D[2]= A[i]+B[j]; { Multiply one term in A with one term in B }
D[3]= A[i+1]+B[j+1]
j=j+2; { goto next element in B }
polyadd(C,D,C) { add the latest multiplied term in D with C and
update C }
end
i=i+2; { Goto next element in A }
j=2; { Goto first element in B }
end
c[1]=c[1]-1; { delete the term –maxint }
end
No comments:
Post a Comment