Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Bai5
- {
- class Program
- {
- static void Main(string[] args)
- {
- int m, n, p;
- int[,] a, b, res;
- string[] temp = Console.ReadLine().Split();
- m = int.Parse(temp[0]);
- n = int.Parse(temp[1]);
- p = int.Parse(temp[2]);
- a = new int[m, n];
- b = new int[n, p];
- res = new int[m, p];
- insertMatrix(a);
- insertMatrix(b);
- task(a, b, res);
- showMatrix(res);
- }
- static void insertMatrix(int[,] a)
- {
- for (int i = 0; i < a.GetLength(0); i++)
- {
- string[] temp = Console.ReadLine().Split();
- for (int j = 0; j < a.GetLength(1); j++)
- {
- a[i, j] = int.Parse(temp[j]);
- }
- }
- }
- static void task(int[,] a, int[,] b, int[,] res)
- {
- for (int i = 0; i < res.GetLength(0); i++)
- {
- for (int j = 0; j < res.GetLength(1); j++)
- {
- res[i, j] = 0;
- for (int k = 0; k < res.GetLength(0); k++)
- {
- res[i, j] += a[i, k] * b[k, j];
- }
- }
- }
- }
- static void showMatrix(int[,] res)
- {
- for (int i = 0; i < res.GetLength(0); i++)
- {
- for (int j = 0; j < res.GetLength(1); j++)
- {
- Console.Write($"{res[i, j]} ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement