ועוד שאלה על קוד שלא עובד טוב
using System; namespace lab3 { /// <summary> /// Demonstrates the use of multi-dimensional arrays. /// </summary> /// <remarks> /// Used in Lab-3 task # 2. /// </remarks> /// public class MatrixMultiply { /// <summary> /// Multiplies two matrixes of size [2,2]. /// </summary> /// <param name="matrix1"></param> /// <param name="matrix2">The 2nd matrix to multiply.</param> /// <returns>The resulting [2,2] matrix of the multiplication.</returns> private static int[,] MultiplyMatrixes(int[,] matrix1, int[,] matrix2) { int[,] result = new int[2, 2]; for ( int rows = 0; rows < result.GetLength(0); rows++ ) for ( int cols = 0; cols < result.GetLength(1); cols++ ) { result[rows,cols] += matrix1[rows,0] * matrix2[0,cols] + matrix1[rows,1] * matrix2[1,cols]; } return result; } /// <summary> /// Populates a matrix of any dimensions from user input. /// </summary> /// <param name="matrix">The matrix to populate.</param> private static void InputMatrix(int[,] matrix) { Console.WriteLine(" PLS insert the metrix "); for (int rows = 0; rows < matrix.GetLength(0); rows++) { for (int colmn = 0; colmn < matrix.GetLength(1); colmn++) { Console.WriteLine(" The current cell {0},{1} ", rows, colmn, " will be :"); matrix[rows, colmn] = Console.Read(); } Console.WriteLine(); } } /// <summary> /// Writes a matrix of any dimensions to the console. /// </summary> /// <param name="matrix">The matrix to write.</param> private static void OutputMatrix(int[,] matrix) { for (int rows = 0; rows < matrix.GetLength(0); rows++) { for (int cols = 0; cols < matrix.GetLength(1); cols++) { Console.Write("{0} ", matrix[rows, cols]); } Console.WriteLine(); } Console.ReadLine(); } /// <summary> /// Multiplies two matrixes of 2,2 size and prints the result. /// </summary> public static void Main() { int[,] matrix1 = new int[2, 2]; int[,] matrix2 = new int[2, 2]; // printing the 1st matrix InputMatrix(matrix1); Console.WriteLine("The input of the 1st matrix is:"); OutputMatrix(matrix1); InputMatrix(matrix2); // printing the 2nd matrix Console.WriteLine("The input of the 2nd matrix is:"); OutputMatrix(matrix2); int[,] resultMultiplying = new int[2, 2]; resultMultiplying = MultiplyMatrixes(matrix1, matrix2); Console.WriteLine("The result of multiplying matrix1 by matrix2 is: "); Output