[ Полезный рекламный блок ]
Попробуйте свои силы в игре, где ваши навыки программирования на C# станут решающим фактором. Переходите по ссылке 🔰.
Перемножение двух матриц можно осуществить следующим образом:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
class Program { static void Main(string[] args) { Console.WriteLine("Введите размерность первой матрицы: "); int[,] A = new int[Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine())]; for (int i = 0; i < A.GetLength(0); i++) { for (int j = 0; j < A.GetLength(1); j++) { Console.Write("A[{0},{1}] = ", i, j); A[i, j] = Convert.ToInt32(Console.ReadLine()); } } Console.WriteLine("Введите размерность второй матрицы: "); int[,] B = new int[Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine())]; for (int i = 0; i < B.GetLength(0); i++) { for (int j = 0; j < B.GetLength(1); j++) { Console.Write("B[{0},{1}] = ", i, j); B[i, j] = Convert.ToInt32(Console.ReadLine()); } } Console.WriteLine("\nМатрица A:"); Print(A); Console.WriteLine("\nМатрица B:"); Print(B); Console.WriteLine("\nМатрица C = A * B:"); int[,] C = Multiplication(A, B); Print(C); } static int[,] Multiplication(int[,] a, int[,] b) { if (a.GetLength(1) != b.GetLength(0)) throw new Exception("Матрицы нельзя перемножить"); int[,] r = new int[a.GetLength(0), b.GetLength(1)]; 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++) { r[i,j] += a[i,k] * b[k,j]; } } } return r; } static void Print(int[,] a) { for (int i = 0; i < a.GetLength(0); i++) { for (int j = 0; j < a.GetLength(1); j++) { Console.Write("{0} ", a[i, j]); } Console.WriteLine(); } } } |


![Как сделать тетрис на [C#] Как сделать тетрис на [C#]](https://dijix.com.ua/blog/wp-content/uploads/2023/03/387403-min-150x150.png)

![Как сделать меню в консоли [C#] Как сделать меню в консоли [C#]](https://dijix.com.ua/blog/wp-content/uploads/2023/03/1-min-150x150.png)
![Как сделать крестики нолики [C#] Как сделать крестики нолики [C#]](https://dijix.com.ua/blog/wp-content/uploads/2023/03/1-min-2-150x150.jpg)
![Как сделать бегущую строку [C#] Как сделать бегущую строку [C#]](https://dijix.com.ua/blog/wp-content/uploads/2023/02/csharp-string-format-post-image-min-150x150.jpg)


