public static void Main(string[] args)
    {
        var myClass       = new AddingPolynomials();
        var myHelperClass = new HelperClass();

        Console.Write("Enter the degree of first polinomial: ");
        int firstPolinomialDegree = int.Parse(Console.ReadLine());

        Console.Write("Enter the degree of second polinomial: ");
        int secondPolinomialDegree = int.Parse(Console.ReadLine());

        int[] firstPolinomial  = myHelperClass.GenerateRandomArray <int>(firstPolinomialDegree + 1, 10);
        int[] secondPolinomial = myHelperClass.GenerateRandomArray <int>(secondPolinomialDegree + 1, 10);

        Console.WriteLine();
        myHelperClass.PrintArray(firstPolinomial);
        Console.WriteLine();

        myHelperClass.PrintArray(secondPolinomial);
        Console.WriteLine();

        int[] sumOfPolinomials = myClass.SumPolinomials(firstPolinomial, secondPolinomial);
        myHelperClass.PrintArray(sumOfPolinomials);
        Console.WriteLine();

        int[] difOfPolinomials = myClass.SubtractPolinomials(firstPolinomial, secondPolinomial);
        myHelperClass.PrintArray(difOfPolinomials);
        Console.WriteLine();
    }
        static void Main()
        {
            int length = int.Parse(Console.ReadLine());

            int[] firstArrayOfNumbers  = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray();
            int[] secondArrayOfNumbers = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray();
            var   resultArray          = AddingPolynomials.AddPolynomials(firstArrayOfNumbers, secondArrayOfNumbers, length);

            // Add
            Console.WriteLine(String.Join(" ", resultArray));
            resultArray = MultiplyPolynomials(firstArrayOfNumbers, secondArrayOfNumbers, length);
            // multiply
            Console.WriteLine(String.Join(" ", resultArray));
            resultArray = SubtractPolynomials(firstArrayOfNumbers, secondArrayOfNumbers, length);
            // Subtract
            Console.WriteLine(String.Join(" ", resultArray));
        }
Example #3
0
        static void Main()
        {
            Console.Write("Please enter your first polynomial degree: ");
            int            input  = int.Parse(Console.ReadLine());
            List <decimal> polOne = new List <decimal>();

            for (int i = 0; i <= input; i++)
            {
                Console.Write("x^{0}= ", input - i);
                polOne.Add(decimal.Parse(Console.ReadLine()));
            }

            Console.Write("Please enter your second polynomial degree: ");
            input = int.Parse(Console.ReadLine());
            List <decimal> polTwo = new List <decimal>();

            for (int i = 0; i <= input; i++)
            {
                Console.Write("x^{0}= ", input - i);
                polTwo.Add(decimal.Parse(Console.ReadLine()));
            }
            if (polOne.Count > polTwo.Count)
            {
                for (int i = 0; i <= polOne.Count - polTwo.Count; i++)
                {
                    polTwo.Insert(0, 0);
                }
            }
            else
            {
                for (int i = 0; i <= polTwo.Count - polOne.Count; i++)
                {
                    polOne.Insert(0, 0);
                }
            }
            Console.WriteLine("\nA-B ->");
            AddingPolynomials.PrintPolinom(Substract(polOne, polTwo));
            Console.WriteLine("\nA*B ->");
            AddingPolynomials.PrintPolinom(Multiplicate(polOne, polTwo));
        }