stefan1919

matrix enter and print

Aug 21st, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 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 ConsoleApplication4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Enter the number of the rows: ");
  14.             int rows = int.Parse(Console.ReadLine());
  15.             Console.WriteLine("Enter the number of the columns: ");
  16.             int cols = int.Parse(Console.ReadLine());
  17.             int[,] matrix = new int[rows, cols];
  18.             Console.WriteLine("Enter the cells: ");
  19.             for (int row = 0; row < rows; row++)
  20.             {
  21.                 for (int col = 0; col < cols; col++)
  22.                 {
  23.                     matrix[row, col] = int.Parse(Console.ReadLine());
  24.                    
  25.                 }
  26.                
  27.             }
  28.             for (int i = 0; i < matrix.GetLength(0); i++)
  29.             {
  30.                 for (int j = 0; j < matrix.GetLength(1); j++)
  31.                 {
  32.                     Console.Write(matrix[i, j]);
  33.                 }
  34.                 Console.WriteLine();
  35.             }
  36.  
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment