Advertisement
elena1234

Read Matrix from the Console

Dec 16th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Matrix
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int rows = int.Parse(Console.ReadLine());
  11.             int cols = int.Parse(Console.ReadLine());
  12.             int[,] matrix = new int[rows, cols];
  13.  
  14.             for ( int row = 0;  row < rows; row ++)
  15.             {
  16.                 int[] currentRow = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  17.                 for (int col = 0; col < cols; col++)
  18.                 {
  19.                     matrix[row, col] = currentRow[col];
  20.                 }
  21.             }                      
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement