Ввести 2 квадратные матрицы и вывести их - C#
Формулировка задачи:
Как ввести 2 матрицы? Помогите пожалуйста.
Решение задачи: «Ввести 2 квадратные матрицы и вывести их»
textual
Листинг программы
- class Program
- {
- public class Matrix
- {
- public float[,] matrix = null;
- public int CountColumn { get; private set; }
- public int CountRow { get; private set; }
- public Matrix(int x = 1, int y = 1)
- {
- matrix = new float[x, y];
- CountColumn = y;
- CountRow = x;
- }
- public float this[int x, int y]
- {
- get { return matrix[x, y]; }
- set { matrix[x, y] = value; }
- }
- public override string ToString()
- {
- StringBuilder ret = new StringBuilder();
- if (matrix == null) return ret.ToString();
- for (int i = 0; i < CountRow; i++)
- {
- for (int t = 0; t < CountColumn; t++)
- {
- ret.Append(matrix[i, t]);
- ret.Append("\t");
- }
- ret.Append("\n");
- }
- return ret.ToString();
- }
- }
- static void Main(string[] args)
- {
- int Row = 2;
- int Column = 2;
- Matrix m1 = new Matrix(Column, Row);
- //ввод
- for (int i = 0; i < Column; i++)
- {
- for (int j = 0; j < Row; j++)
- {
- Console.WriteLine("add [{0},{1}] element of matrix ", i, j);
- string s = Console.ReadLine();
- m1.matrix[i, j] = Convert.ToSingle(s);
- }
- }
- //вывод
- Console.WriteLine("{0}", m1);
- Console.ReadKey(true);
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д