static void Main(string[] args) { Polynomial a = new Polynomial(); Polynomial b = new Polynomial(); a.ReadPolynomial(); b.ReadPolynomial(); Polynomial result = a + b; Console.WriteLine(result.ToString()); }
public static Polynomial operator +(Polynomial x, Polynomial y) { int biggerDegree = Math.Max(x.PolynomialDegree, y.PolynomialDegree); Polynomial result = new Polynomial(); double tmp = 0.0; for (int i = 0; i <= biggerDegree; ++i) { tmp = 0.0; if (i <= x.PolynomialDegree) { tmp += x[i]; } if (i <= y.PolynomialDegree) { tmp += y[i]; } result.AddCoefficient(tmp); } result.Normalize(); return result; }