Let P1 and P2 are two polynominals..
where
p1 = 1 + 4X^2 + x^4
and
p2 = 2x^2 + x^4
program is to multiply p1 with p2
p3 = p1 * p2
Like
line 1: ( 1 + 4x^2 + x^4) (2x^2 + x^4)
line 2: 1*(2x^2 + x^4) + 4x^2 * (2x^2 + x^4) + x^4 * (2x^2 + x^4)
line 3: 2x^2 + x^4 + 8x^4 + 4x^6 + 2x^6 + x^8
line 4: 2x^2 + 9x^4 + 6x^6 + x^8
I am stucked in obtaining line 4..
here is my Polynominal
typedef struct termType
{
int coeff,expo;
}termType;
typedef struct poly
{
termType terms[20];
int noOfTerms;
}poly;
and my multiplication function
void mul(poly p1,poly p2,poly *p3)
{
poly p4;
int i,j,k=0;
for(i=0;i<p1.noOfTerms;i++)
{
for(j=0;j<p2.noOfTerms;j++,k++)
{
p4.terms[k].coeff = p1.terms[i].coeff * p2.terms[j].coeff;
p4.terms[k].expo = p1.terms[i].expo + p2.terms[j].expo;
}
}
p4.noOfTerms = k;
// line 4 code............
}
Any Help Will be Appriciated
Thanks
Vinit Mittal