public static Polinom operator+(Polinom first, Polinom second) { if (first.Power > second.Power) { Polinom resPolinom = new Polinom(first.Power); for (int i = 0; i < first.Odds.Length; i++) { if (i < second.Odds.Length) { resPolinom.Odds[i] = first.Odds[i] + second.Odds[i]; } else { resPolinom.Odds[i] = first.Odds[i]; } } return(resPolinom); } else { Polinom resPolinom = new Polinom(second.Power); for (int i = 0; i < second.Odds.Length; i++) { if (i < first.Odds.Length) { resPolinom.Odds[i] = first.Odds[i] + second.Odds[i]; } else { resPolinom.Odds[i] = second.Odds[i]; } } return(resPolinom); } }
public static Polinom operator*(Polinom polinom, int num) { Polinom resPolinom = new Polinom(polinom.Odds); for (int i = 0; i < polinom.Odds.Length; i++) { resPolinom.Odds[i] = polinom.Odds[i] * num; } return(resPolinom); }
public static Polinom operator*(Polinom first, Polinom second) { Polinom resPolinom = new Polinom(first.Power + second.Power); for (int i = 0; i < first.Odds.Length; i++) { for (int j = 0; j < second.Odds.Length; j++) { resPolinom.Odds[i + j] += first.Odds[i] * second.Odds[j]; } } return(resPolinom); }
static void Main(string[] args) { Polinom p = new Polinom(1, 2); p.printPolinom(); Polinom p2 = new Polinom(2, 2); p2.printPolinom(); /* Polinom p3 = p + p2; * p3.printPolinom(); * * Polinom p4 = p - p2; * p4.printPolinom();*/ Polinom p5 = p * p2; p5.printPolinom(); Console.ReadKey(); }