Advertisement
Qrist

Reading Matrix from the Console

Jul 11th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp3
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.Write("Row = ");
  10.             int row = int.Parse(Console.ReadLine());
  11.             Console.Write("Column = ");
  12.             int col = int.Parse(Console.ReadLine());
  13.             int[,] arr = new int[row, col];
  14.  
  15.             for (int i = 0; i < row; i++)
  16.             {
  17.                 for (int j = 0; j < col; j++)
  18.                 {
  19.                     Console.Write("arr[{0},{1}] = ",i,j);
  20.                     arr[i,j] = int.Parse(Console.ReadLine());
  21.  
  22.                 }
  23.             }
  24.  
  25.             for (int i = 0; i < arr.GetLength(0); i++)
  26.             {
  27.                 for (int j = 0; j < arr.GetLength(1); j++)
  28.                 {
  29.                     Console.Write(arr[i,j] + " ");
  30.                 }
  31.                 Console.WriteLine();
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement