using System;
namespace Test
{
public class T
{
public static void MultiplyMatrix()
{
Random ran = new Random();
int[,] a = new int[2, 3];
// Инициализируем данный массив
for (int i = 0; i < a.GetLength(0); i++)
{
for (int j = 0; j < a.GetLength(1); j++)
{
a[i, j] = ran.Next(1, 15);
}
}
//вывод матрицы а
Console.Write("Матрица A: \n ");
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();
}
int[,] b = new int[3, 2];
// Инициализируем данный массив
for (int i = 0; i < b.GetLength(0); i++)
{
for (int j = 0; j < b.GetLength(1); j++)
{
b[i, j] = ran.Next(1, 15);
}
}
//вывод матрицы b
Console.Write("Матрица B: \n ");
for (int i = 0; i < b.GetLength(0); i++)
{
for (int j = 0; j < b.GetLength(1); j++)
{
Console.Write("{0} ", b[i, j]); // крутой вывод
}
Console.WriteLine();
}
int[,] c = new int[a.GetLength(0), b.GetLength(1)];
if (a.GetLength(1) == b.GetLength(0))
{
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++)
{
c[i, j] += a[i, k] * b[k, j];
}
}
}
}
else
{
Console.WriteLine(
"\n Количество столбцов матрицы А неравно количеству строк матрицы B! \n ");
Environment.Exit(-1);
}
Console.Write("Сумма матриц A и B = C: \n ");
for (int i = 0; i < c.GetLength(0); i++)
{
for (int j = 0; j < c.GetLength(1); j++)
{
//Console.Write("C[{0},{1}] : {2}", i, j, c[i, j]); - хуёвый вывод
Console.Write("{0} ", c[i, j]); // крутой вывод
}
Console.WriteLine();
}
}
public static void Main()
{
MultiplyMatrix();
}
}
}
ICAgIHVzaW5nIFN5c3RlbTsKICAgICAKICAgIG5hbWVzcGFjZSBUZXN0CiAgICB7CiAgICAgICAgcHVibGljIGNsYXNzIFQKICAgICAgICB7CiAgICAgICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNdWx0aXBseU1hdHJpeCgpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIFJhbmRvbSByYW4gPSBuZXcgUmFuZG9tKCk7CiAgICAgICAgICAgICAgICBpbnRbLF0gYSA9IG5ldyBpbnRbMiwgM107CiAgICAgICAgICAgICAgICAvLyDQmNC90LjRhtC40LDQu9C40LfQuNGA0YPQtdC8INC00LDQvdC90YvQuSDQvNCw0YHRgdC40LIKICAgICAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgYS5HZXRMZW5ndGgoMCk7IGkrKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IGEuR2V0TGVuZ3RoKDEpOyBqKyspCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBhW2ksIGpdID0gcmFuLk5leHQoMSwgMTUpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAvL9Cy0YvQstC+0LQg0LzQsNGC0YDQuNGG0Ysg0LAKICAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlKCLQnNCw0YLRgNC40YbQsCBBOiBcbiAiKTsgIAogICAgICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBhLkdldExlbmd0aCgwKTsgaSsrKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBhLkdldExlbmd0aCgxKTsgaisrKQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlKCJ7MH0gICAiLCBhW2ksIGpdKTsgICAvLyDQutGA0YPRgtC+0Lkg0LLRi9Cy0L7QtAogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBpbnRbLF0gYiA9IG5ldyBpbnRbMywgMl07CiAgICAgICAgICAgICAgICAvLyDQmNC90LjRhtC40LDQu9C40LfQuNGA0YPQtdC8INC00LDQvdC90YvQuSDQvNCw0YHRgdC40LIKICAgICAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgYi5HZXRMZW5ndGgoMCk7IGkrKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IGIuR2V0TGVuZ3RoKDEpOyBqKyspCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBiW2ksIGpdID0gcmFuLk5leHQoMSwgMTUpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvL9Cy0YvQstC+0LQg0LzQsNGC0YDQuNGG0YsgYgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGUoItCc0LDRgtGA0LjRhtCwIEI6IFxuICIpOyAgCiAgICAgICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IGIuR2V0TGVuZ3RoKDApOyBpKyspCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IGIuR2V0TGVuZ3RoKDEpOyBqKyspCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGUoInswfSAgICIsIGJbaSwgal0pOyAgIC8vINC60YDRg9GC0L7QuSDQstGL0LLQvtC0CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgICAgICAgICAgCiAgICAgCiAgICAgICAgICAgICAgICBpbnRbLF0gYyA9IG5ldyBpbnRbYS5HZXRMZW5ndGgoMCksIGIuR2V0TGVuZ3RoKDEpXTsKICAgICAgICAgICAgICAgIGlmIChhLkdldExlbmd0aCgxKSA9PSBiLkdldExlbmd0aCgwKSkKICAgICAgICAgICAgICAgIHsKICAgICAKICAgICAgICAgICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IGEuR2V0TGVuZ3RoKDApOyBpKyspCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IGIuR2V0TGVuZ3RoKDEpOyBqKyspCiAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaW50IGsgPSAwOyBrIDwgYi5HZXRMZW5ndGgoMCk7IGsrKykKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjW2ksIGpdICs9IGFbaSwga10gKiBiW2ssIGpdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKAogICAgICAgICAgICAgICAgICAgICAgICAiXG4g0JrQvtC70LjRh9C10YHRgtCy0L4g0YHRgtC+0LvQsdGG0L7QsiDQvNCw0YLRgNC40YbRiyDQkCDQvdC10YDQsNCy0L3QviDQutC+0LvQuNGH0LXRgdGC0LLRgyDRgdGC0YDQvtC6INC80LDRgtGA0LjRhtGLIEIhIFxuICAiKTsKICAgICAgICAgICAgICAgICAgICBFbnZpcm9ubWVudC5FeGl0KC0xKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGUoItCh0YPQvNC80LAg0LzQsNGC0YDQuNGGIEEg0LggQiA9IEM6IFxuICIpOyAgCiAgICAgICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IGMuR2V0TGVuZ3RoKDApOyBpKyspCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBjLkdldExlbmd0aCgxKTsgaisrKQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAvL0NvbnNvbGUuV3JpdGUoIkNbezB9LHsxfV0gOiB7Mn0iLCBpLCBqLCBjW2ksIGpdKTsgLSDRhdGD0ZHQstGL0Lkg0LLRi9Cy0L7QtAogICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGUoInswfSAgICIsIGNbaSwgal0pOyAgIC8vINC60YDRg9GC0L7QuSDQstGL0LLQvtC0CgogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgCiAgICAgICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgTXVsdGlwbHlNYXRyaXgoKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0=