61 lines
1.3 KiB
C#
61 lines
1.3 KiB
C#
using System;
|
|
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
int[,] m1 = new int[2, 2];
|
|
int[,] m2 = new int[2, 2];
|
|
|
|
fillQuadraticMatrix(ref m1, 2);
|
|
fillQuadraticMatrix(ref m2, 2);
|
|
|
|
int[,] res = multiplyQuadraticMatrix(m1, m2, 2);
|
|
|
|
printQuadraticMatrix(res, 2);
|
|
}
|
|
|
|
static void fillQuadraticMatrix(ref int[,] m, int n)
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
Console.Write("m[{0}][{1}] = ", i, j);
|
|
m[i, j] = int.Parse(Console.ReadLine());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
static void printQuadraticMatrix(int[,] m, int n)
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
Console.Write(m[i, j] + " ");
|
|
}
|
|
Console.Write("\n");
|
|
}
|
|
}
|
|
|
|
static int[,] multiplyQuadraticMatrix(int[,] m1, int[,] m2, int n)
|
|
{
|
|
int[,] res = new int[n, n];
|
|
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
for (int j = 0; j < n; j++)
|
|
{
|
|
for (int k = 0; k < n; k++)
|
|
{
|
|
res[i, j] += m1[i, k] * m2[k, j];
|
|
}
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
}
|