public static Polinom operator -(Polinom arg1, Polinom arg2) { int n = 0; int k = 0; if (arg1.coeficients.Length > arg2.coeficients.Length) { n = arg2.coeficients.Length; k = -1; Array.Resize(ref arg2.coeficients, arg1.coeficients.Length); } if (arg1.coeficients.Length < arg2.coeficients.Length) { n = arg1.coeficients.Length; k = 1; Array.Resize(ref arg1.coeficients, arg2.coeficients.Length); } Polinom substraction = new Polinom(arg2.coeficients.Length); for (int i = 0; i < arg2.coeficients.Length; i++) { substraction[i] = arg1[i] - arg2[i]; } if (k == -1) { Array.Resize(ref arg2.coeficients, n); } if (k == 1) { Array.Resize(ref arg1.coeficients, n); } return(substraction); }
public static Polinom operator *(Polinom polynom1, Polinom polynom2) { Polinom multiplication = new Polinom(polynom1.coeficients.Length + polynom2.coeficients.Length - 1); for (int i = 0; i < polynom1.coeficients.Length; ++i) { for (int j = 0; j < polynom2.coeficients.Length; ++j) { multiplication[i + j] += polynom1.coeficients[i] * polynom2.coeficients[j]; } } return(multiplication); }
static void Main(string[] args) { Polinom first = new Polinom(3); first.Putcoefs(new int[] { 1, -2, 3 }); Console.WriteLine(first); Polinom second = new Polinom(3); second.Putcoefs(new int[] { 1, 2, 3 }); // Polinom sum = first + second; //sum.Showpolinom(); //Polinom substract = first - second; //substract.Showpolinom(); Polinom multiplication = first * second; // Console.WriteLine("enter a power of what coef you want to know"); //int n = Convert.ToInt32(Console.ReadLine()); //Console.WriteLine( first.Getcoefs(n) ); }