MatrixOutput IService.MatrixSum(MatrixInput Input) { MatrixT <int> A = new MatrixT <int>(new int[Input.matrix1[0].Length, Input.matrix1[1].Length]); MatrixT <int> B = new MatrixT <int>(new int[Input.matrix2[0].Length, Input.matrix2[1].Length]); for (int i = 0; i < Input.matrix1[0].Length; i++) { for (int j = 0; j < Input.matrix1[1].Length; j++) { A[i, j] = Input.matrix1[i][j]; } } for (int i = 0; i < Input.matrix2[0].Length; i++) { for (int j = 0; j < Input.matrix2[1].Length; j++) { B[i, j] = Input.matrix2[i][j]; } } MatrixT <int> MatResult = A + B; MatrixOutput result = new MatrixOutput(); result.matrixResult = new int[Input.matrix1[0].Length][]; for (int i = 0; i < Input.matrix1[1].Length; i++) { result.matrixResult[i] = new int[Input.matrix1[0].Length]; } int[][] ansArr = new int[Input.matrix1[0].Length][]; for (int i = 0; i < Input.matrix1[1].Length; i++) { ansArr[i] = new int[Input.matrix1[0].Length]; } for (int i = 0; i < Input.matrix1[0].Length; i++) { for (int j = 0; j < Input.matrix1[1].Length; j++) { ansArr[i][j] = MatResult[i, j]; } } result.matrixResult = ansArr; return(result); }
static void Main(string[] args) { MatrixInput input = new MatrixInput(); input.matrix1 = new int[2][]; for (int i = 0; i < 2; i++) { input.matrix1[i] = new int[2]; } input.matrix2 = new int[2][]; for (int i = 0; i < 2; i++) { input.matrix2[i] = new int[2]; } for (int i = 0; i < input.matrix1[0].Length; i++) { for (int j = 0; j < input.matrix1[0].Length; j++) { input.matrix1[i][j] = 1; input.matrix2[i][j] = 2; } } ServiceClient client = new ServiceClient(); MatrixOutput output = client.MatrixMul(input); Console.WriteLine("Исходные матрицы:"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { Console.Write(input.matrix1[i][j]); } Console.WriteLine(); } for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { Console.Write(input.matrix2[i][j]); } Console.WriteLine(); } Console.WriteLine("Ответ:"); int[][] otv = output.matrixResult; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { Console.Write(otv[i][j]); } Console.WriteLine(); } Console.ReadKey(); }