Polynomial - Polynomial c = new Polynomial(0, a.degree +...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
public class Polynomial { private int[] coef; // coefficients private int degree; // degree of polynomial (-1 for the zero polynomial) public Polynomial times(Polynomial b) { Polynomial a = this; if (a.degree == -1 || b.degree == -1) return new Polynomial(0, 0);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Polynomial c = new Polynomial(0, a.degree + b.degree); for (int i = 0; i <= a.degree; i++) for (int j = 0; j <= b.degree; j++) c.coef[i+j] += (a.coef[i] * b.coef[j]); c.degree = a.degree + b.degree; return c; } }...
View Full Document

This note was uploaded on 10/12/2009 for the course CSC CSC 110 taught by Professor Anne during the Fall '04 term at University of Victoria.

Ask a homework question - tutors are online