Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Demo
- {
- class Program
- {
- static void Main(string[] args)
- {
- //variant1
- var matrixA = new int[,]
- {
- { 1, 2, 3 },
- { 4, 5, 6 },
- { 7, 8, 9 }
- };
- var matrixB = new int[,]
- {
- { 0, 1, 0 },
- { 7, 3, 4 },
- { 2, 6, 3 }
- };
- var matrixC = new int[3, 3];
- int sum = 0;
- for (int row = 0; row < matrixA.GetLength(0); row++)
- {
- for (int col = 0; col < matrixB.GetLength(1); col++)
- {
- for (int k = 1; k <= 3; k++)
- {
- sum += matrixA[row, k - 1] * matrixB[k - 1, col];
- }
- matrixC[row, col] = sum;
- sum = 0;
- }
- }
- for (int i = 0; i < matrixC.GetLength(0); i++)
- {
- for (int j = 0; j < matrixC.GetLength(1); j++)
- {
- Console.Write(matrixC[i, j] + " ");
- }
- Console.WriteLine();
- }
- //Variant2
- var matrixA = new int[,]
- {
- { 1, 2, 3 },
- { 4, 5, 6 },
- { 7, 8, 9 }
- };
- var matrixB = new int[,]
- {
- { 0, 1, 0 },
- { 7, 3, 4 },
- { 2, 6, 3 }
- };
- var matrixC = new int[3, 3];
- for (int row = 0; row < matrixA.GetLength(0); row++)
- {
- for (int col = 0; col < matrixB.GetLength(1); col++)
- {
- matrixC[row, col] = 0;
- for (int k = 0; k < 3; k++)
- {
- matrixC[row, col] += matrixA[row, k] * matrixB[k, col];
- }
- }
- }
- for (int row = 0; row < matrixC.GetLength(0); row++)
- {
- for (int col = 0; col < matrixC.GetLength(1); col++)
- {
- Console.Write(matrixC[row, col] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement