/// <summary> /// Subroutine to demonstrate Task1_2 /// 1.2. Создать метод, принимающий две матрицы и возвращающий их сумму /// </summary> internal static void Task1_2() { Console.WriteLine("\n1.2. Создать метод, принимающий две матрицы и возвращающий их сумму."); var rows = Dialogues.RequestByte("\nPlease enter a number of rows for a matrix."); var columns = Dialogues.RequestByte("\nPlease enter a number of columns for the matrix."); var firstMatrix = Matrix.GenerateMatrix(rows, columns, -rows, columns); Matrix.PrintMatrix(firstMatrix, "\nThe first addend matrix:"); //Kinda have to sleep the thread to get another set of values from random generator Thread.Sleep(10); var secondMatrix = Matrix.GenerateMatrix(rows, columns, -rows, columns); Matrix.PrintMatrix(secondMatrix, "\nThe second addend matrix:"); if (Matrix.ValidateMatrixOperation(firstMatrix, secondMatrix)) { Matrix.PrintMatrix(Matrix.AddMatrices(firstMatrix, secondMatrix), "\nResult matrix after addition:"); Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); } else { Console.WriteLine("\nWould you like to change the input values (yes/no)?"); while (Console.ReadLine() == "yes") { Task1_2(); Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); } } }
/// <summary> /// Subroutine to demonstrate Task1_1 /// 1.1. Создать метод, принимающий число и матрицу, возвращающий матрицу умноженную на число /// </summary> internal static void Task1_1() { Console.WriteLine("\n1.1. Создать метод, принимающий число и матрицу, возвращающий матрицу умноженную на число."); var rows = Dialogues.RequestByte("\nPlease enter a number of rows for a matrix."); var columns = Dialogues.RequestByte("\nPlease enter a number of columns for the matrix."); var firstMatrix = Matrix.GenerateMatrix(rows, columns, -rows, columns); Matrix.PrintMatrix(firstMatrix, "\nThe matrix:"); var scalar = Dialogues.RequestInt("\nPlease enter a scalar to multiply the first matrix by."); if (Matrix.ValidateMatrixOperation(firstMatrix, scalar)) { Matrix.PrintMatrix(Matrix.MultiplyMatrixByScalar(firstMatrix, scalar), "\nResult matrix multiplied by the scalar:"); Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); } else { Console.WriteLine("\nWould you like to change the input values (yes/no)?"); while (Console.ReadLine() == "yes") { Task1_1(); Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); } } }
/// <summary> /// Subroutine to demonstrate Task1_4 /// 1.4. Создать метод, принимающий две матрицы, возвращающий их произведение /// </summary> internal static void Task1_4() { Console.WriteLine("\n1.4. Создать метод, принимающий две матрицы, возвращающий их произведение."); var rows = Dialogues.RequestByte("\nPlease enter a number of rows for a matrix."); var columns = Dialogues.RequestByte("\nPlease enter a number of columns for the matrix."); var firstMatrix = Matrix.GenerateMatrix(rows, columns, -rows, columns); Matrix.PrintMatrix(firstMatrix, "\nThe left matrix:"); //Kinda have to sleep the thread to get another set of values from random generator Thread.Sleep(10); var rowsSecond = Dialogues.RequestByte("\nPlease enter a number of rows for the second matrix."); while (columns != rowsSecond) { Console.WriteLine("Multiplication of two matrices is defined if and only if the number of columns of the left matrix is the same as the number of rows of the right matrix."); rowsSecond = Dialogues.RequestByte("\nPlease enter a number of rows for the second matrix."); } var columnsSecond = Dialogues.RequestByte("\nPlease enter a number of columns for the second matrix."); var secondMatrix = Matrix.GenerateMatrix(rowsSecond, columnsSecond, -rowsSecond, columnsSecond); Matrix.PrintMatrix(secondMatrix, "\nThe right matrix:"); if (Matrix.ValidateMatrixOperation(firstMatrix, secondMatrix, true)) { Matrix.PrintMatrix(Matrix.MultiplyMatrices(firstMatrix, secondMatrix), "\nFirst Matrix x Second matrix:"); Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); } else { Console.WriteLine("\nWould you like to change the input values (yes/no)?"); while (Console.ReadLine() == "yes") { Task1_4(); Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); } } }