distributed-computing/tasks/grenaderova-aa/lab_5/5LABA/Controller.cs

66 lines
1.6 KiB
C#
Raw Permalink Normal View History

2023-12-18 16:34:36 +04:00
using System.Drawing;
namespace 5LABA
{
public class Controller
{
public string PrintResultMatrix(int[,] result)
{
string resultString = "";
for (int i = 0; i < result.GetLength(0); i++)
{
for (int j = 0; j < result.GetLength(1); j++)
{
resultString += result[i, j];
if (j != result.GetLength(1) - 1)
{
resultString += " ";
}
}
resultString += Environment.NewLine;
}
return resultString;
}
public int[,] GetMatrixFromTextbox(string inputText)
{
string[] lines = inputText.Split(Environment.NewLine);
int numRows = lines.Length;
int numCol = lines[0].Split(' ').Length;
int[,] matrix = new int[numRows, numCol];
for (int i = 0; i < numRows; i++)
{
string[] elements = lines[i].Split(' ');
for (int j = 0; j < numCol; j++)
{
matrix[i, j] = int.Parse(elements[j]);
}
}
return matrix;
}
public int[,] GenerateNewMatrix(int count)
{
Random random = new Random();
int[,] matrix = new int[count, count];
for (int i = 0; i < count; i++)
{
for (int j = 0; j < count; j++)
{
matrix[i, j] = random.Next(1, 26);
}
}
return matrix;
}
}
}