Ввести 2 квадратные матрицы и вывести их - C#

Узнай цену своей работы

Формулировка задачи:

Как ввести 2 матрицы? Помогите пожалуйста.

Решение задачи: «Ввести 2 квадратные матрицы и вывести их»

textual
Листинг программы
  1.     class Program
  2.     {
  3.         public class Matrix
  4.         {
  5.             public float[,] matrix = null;
  6.  
  7.             public int CountColumn { get; private set; }
  8.             public int CountRow { get; private set; }
  9.  
  10.             public Matrix(int x = 1, int y = 1)
  11.             {
  12.                 matrix = new float[x, y];
  13.  
  14.                 CountColumn = y;
  15.                 CountRow = x;
  16.             }
  17.  
  18.             public float this[int x, int y]
  19.             {
  20.                 get { return matrix[x, y]; }
  21.                 set { matrix[x, y] = value; }
  22.             }
  23.             public override string ToString()
  24.             {
  25.                 StringBuilder ret = new StringBuilder();
  26.                 if (matrix == null) return ret.ToString();
  27.  
  28.                 for (int i = 0; i < CountRow; i++)
  29.                 {
  30.                     for (int t = 0; t < CountColumn; t++)
  31.                     {
  32.                         ret.Append(matrix[i, t]);
  33.                         ret.Append("\t");
  34.                     }
  35.                     ret.Append("\n");
  36.                 }
  37.                 return ret.ToString();
  38.             }
  39.         }
  40.         static void Main(string[] args)
  41.         {
  42.             int Row = 2;
  43.             int Column = 2;
  44.             Matrix m1 = new Matrix(Column, Row);
  45.             //ввод
  46.             for (int i = 0; i < Column; i++)
  47.             {
  48.                 for (int j = 0; j < Row; j++)
  49.                 {
  50.                     Console.WriteLine("add [{0},{1}] element of matrix ", i, j);
  51.                     string s = Console.ReadLine();
  52.                     m1.matrix[i, j] = Convert.ToSingle(s);
  53.  
  54.                 }
  55.             }
  56.             //вывод
  57.             Console.WriteLine("{0}", m1);
  58.             Console.ReadKey(true);
  59.         }
  60.     }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

10   голосов , оценка 4.3 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы