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 ConsoleApplication6
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[,] matrixFirst = {
- {1, 2},
- {3, 4},
- {5, 6},
- {7, 8}
- };
- int[,] matrixSecond = {
- {1, 2, 3},
- {4, 5, 6}
- };
- int firstRow = matrixFirst.GetLength(0);
- int firstCol = matrixFirst.GetLength(1);
- int secondRow = matrixSecond.GetLength(0);
- int secondCol = matrixSecond.GetLength(1);
- int[,] matrixResult = new int[firstRow, secondCol];
- for (int rows = 0; rows < firstRow; rows++)
- {
- for (int cols = 0; cols < secondCol; cols++)
- {
- int sum = 0;
- for (int i = 0; i < firstCol; i++)
- {
- sum += matrixFirst[rows, i] * matrixSecond[i, cols];
- }
- matrixResult[rows, cols] = sum;
- }
- }
- for (int i = 0; i < matrixResult.GetLength(0); i++)
- {
- for (int j = 0; j < matrixFirst.GetLength(1); j++)
- {
- Console.Write(matrixResult[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment