using System;
public class Matrix
{
static void Main(string[] args)
{
int N = 0;
int M = 0;
Console.WriteLine("Введите количество строк N: ");
N = int.Parse(Console.ReadLine());
Console.WriteLine("Введите количество строк N: ");
M = int.Parse(Console.ReadLine());
Console.WriteLine("Исходная матрица: ");
Console.WriteLine();
int[,] sample = new int[N, M];
Random rnd = new Random();
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
sample[i, j] = rnd.Next(1, 100); // заполнение матрицы случайными числами
Console.Write(sample[i, j] + " \t ");
}
Console.WriteLine();
}
int[,] trans = new int[M, N];
Console.WriteLine();
Console.WriteLine("Транспонированная матрица: ");
Console.WriteLine();
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
trans[i, j] = sample[j, i];
Console.Write(trans[i, j] + " \t ");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIE1hdHJpeAp7CglzdGF0aWMgdm9pZCBNYWluKHN0cmluZ1tdIGFyZ3MpCiAgICAgICAgewogICAgICAgIAlpbnQgTiA9IDA7CiAgICAgICAgICAgIGludCBNID0gMDsKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoItCS0LLQtdC00LjRgtC1INC60L7Qu9C40YfQtdGB0YLQstC+INGB0YLRgNC+0LogTjogIik7CgkJCU4gPSBpbnQuUGFyc2UoQ29uc29sZS5SZWFkTGluZSgpKTsKCQkJQ29uc29sZS5Xcml0ZUxpbmUoItCS0LLQtdC00LjRgtC1INC60L7Qu9C40YfQtdGB0YLQstC+INGB0YLRgNC+0LogTjogIik7CgkJCU0gPSBpbnQuUGFyc2UoQ29uc29sZS5SZWFkTGluZSgpKTsKICAgICAgICAgICAKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoItCY0YHRhdC+0LTQvdCw0Y8g0LzQsNGC0YDQuNGG0LA6ICIpOwogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgpOwogICAgICAgICAgICBpbnRbLF0gc2FtcGxlID0gbmV3IGludFtOLCBNXTsKICAgICAgICAgICAgUmFuZG9tIHJuZCA9IG5ldyBSYW5kb20oKTsKIAogICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IE47IGkrKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBNOyBqKyspCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgc2FtcGxlW2ksIGpdID0gcm5kLk5leHQoMSwgMTAwKTsgLy8g0LfQsNC/0L7Qu9C90LXQvdC40LUg0LzQsNGC0YDQuNGG0Ysg0YHQu9GD0YfQsNC50L3Ri9C80Lgg0YfQuNGB0LvQsNC80LgKICAgICAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlKHNhbXBsZVtpLCBqXSArICIgXHQgIik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGludFssXSB0cmFucyA9IG5ldyBpbnRbTSwgTl07CiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCk7CiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCLQotGA0LDQvdGB0L/QvtC90LjRgNC+0LLQsNC90L3QsNGPINC80LDRgtGA0LjRhtCwOiAiKTsKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoKTsKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBNOyBpKyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgTjsgaisrKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHRyYW5zW2ksIGpdID0gc2FtcGxlW2osIGldOwogICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGUodHJhbnNbaSwgal0gKyAiIFx0ICIpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBDb25zb2xlLlJlYWRMaW5lKCk7CiAgICAgICAgfQp9