using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace OperationsMatrix { public class Matrix { private int[,] grid; private int countRow; private int countCol; public static Matrix SetColAndRow(int countRows, int countCols) { return new Matrix(countRows, countCols); } private Matrix(int countRows, int countCols) { this.grid = new int[countRows, countCols]; this.countRow = countRows; this.countCol = countCols; } public void FillRandomNumber(int min, int max) { // Небольшая задержка, чтобы гарантировать уникальность создаваемых чисел Thread.Sleep(150); Random randNumber = new Random(); for (int i = 0; i < this.countRow; i++) for (int j = 0; j < this.countCol; j++) { this.grid[i, j] = randNumber.Next(min, max); } } public Matrix Add(Matrix MatrixB) { Matrix resultMatrix = SetColAndRow(this.countRow, this.countCol); int result; for (int i = 0; i < this.countRow; i++) for (int j = 0; j < this.countCol; j++) { result = this.grid[i, j] + MatrixB.GetElementValue(i, j); resultMatrix.SetElementValue(i, j, result); } return resultMatrix; } public Matrix Sub(Matrix MatrixB) { Matrix resultMatrix = SetColAndRow(this.countRow, this.countCol); int result; for (int i = 0; i < this.countRow; i++) for (int j = 0; j < this.countCol; j++) { result = this.grid[i, j] - MatrixB.GetElementValue(i, j); resultMatrix.SetElementValue(i, j, result); } return resultMatrix; } public int GetElementValue(int row, int col) { return this.grid[row, col]; } public void SetElementValue(int row, int col, int val) { this.grid[row, col] = val; } public int GetCountRow() { return this.countRow; } public int GetCountCol() { return this.countCol; } public int[,] GetMatrix() { return this.grid; } } }