Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Polynomial* GCD(struct Polynomial* a, struct Polynomial* b) {
- struct Polynomial* temp = makePolynomial(a->deg);
- while (b->deg != 0 || fabs(b->coeff[0]) > ZERO) {
- for(int i = 0; i < a->deg + 1; i++)
- temp->coeff[i] = a->coeff[i];
- a->deg = b->deg;
- a->coeff = realloc(a->coeff, (a->deg+1)*sizeof(*a->coeff));
- for(int i = 0; i < a->deg + 1; i++)
- a->coeff[i] = b->coeff[i];
- dividePolynomials(temp, b, b);
- temp->deg = a->deg;
- temp->coeff = realloc(temp->coeff, (a->deg + 1) * sizeof(*temp->coeff));
- }
- findDeg(a);
- free(temp);
- return a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement