Advertisement
Guest User

[C#] Multidimentional Arrays - Task 1A

a guest
Jul 20th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 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. class PrintMatrix
  8. {
  9.     static void Main()
  10.     {
  11.         Console.ForegroundColor = ConsoleColor.White;
  12.         int n = int.Parse(Console.ReadLine());
  13.         int[,] matrix = new int[n, n];
  14.         for (int rows = 0; rows < matrix.GetLength(0); rows++)
  15.         {
  16.             for (int cols = 0; cols < matrix.GetLength(1); cols++)
  17.             {
  18.                 matrix[rows, cols] = rows + 1 + (cols * n);
  19.             }
  20.         }
  21.         for (int i = 0; i < matrix.GetLength(0); i++)
  22.         {
  23.             for (int j = 0; j < matrix.GetLength(1); j++)
  24.             {
  25.                 Console.Write(matrix[i,j] + "  ");
  26.             }
  27.             Console.WriteLine();
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement