using System; namespace Test { public class T { public static void MultiplyMatrix() { Random ran = new Random(); int[,] a = new int[4, 5]; // Инициализируем данный массив for (int i = 0; i < a.GetLength(0); i++) { for (int j = 0; j < a.GetLength(1); j++) { a[i, j] = ran.Next(1, 15); } } int[,] b = new int[5, 4]; // Инициализируем данный массив for (int i = 0; i < b.GetLength(0); i++) { for (int j = 0; j < b.GetLength(1); j++) { b[i, j] = ran.Next(1, 15); } } int[,] c = new int[a.GetLength(0), b.GetLength(1)]; if (a.GetLength(1) == b.GetLength(0)) { for (int i = 0; i < a.GetLength(0); i++) { for (int j = 0; j < b.GetLength(1); j++) { for (int k = 0; k < b.GetLength(0); k++) { c[i, j] += a[i, k] * b[k, j]; } } } } else { Console.WriteLine( "\n Number of columns in First Matrix should be equal to Number of rows in Second Matrix."); Console.WriteLine("\n Please re-enter correct dimensions."); Environment.Exit(-1); } for (int i = 0; i < c.GetLength(0); i++) { for (int j = 0; j < c.GetLength(1); j++) { Console.Write("C[{0},{1}] : {2}", i, j, c[i, j]); } Console.WriteLine(); } } public static void Main() { MultiplyMatrix(); } } }