TheBulgarianWolf

Matrix by the user

Dec 16th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace arraysExample
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.            
  14.             Console.WriteLine("Creating a matrix(By user input).");
  15.             Console.Write("Enter the number of the rows in the matrix: ");
  16.             int rows = int.Parse(Console.ReadLine());
  17.             Console.Write("Enter the number of the columns in the matrix: ");
  18.             int cols = int.Parse(Console.ReadLine());
  19.             int[,] matrix = new int[rows,cols];
  20.             Console.WriteLine("Enter the cells of the matrix: ");
  21.             for(int row = 0; row < rows; row++)
  22.             {
  23.                 for(int col = 0; col < cols; col++)
  24.                 {
  25.                     Console.Write("Matrix[{0},{1}] = ", row, col);
  26.                     matrix[row, col] = int.Parse(Console.ReadLine());
  27.                 }
  28.             }
  29.  
  30.             for(int row = 0; row < matrix.GetLength(0); row++)
  31.             {
  32.                 for(int col = 0; col < matrix.GetLength(1); col++)
  33.                 {
  34.                     Console.Write(" " + matrix[row,col]);
  35.                 }
  36.                 Console.WriteLine();
  37.             }
  38.             Console.ReadLine();
  39.         }
  40.     }
  41. }
Add Comment
Please, Sign In to add comment