Advertisement
Teodor92

MultiArray.1A

Jan 22nd, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2.  
  3. class Matrix
  4. {
  5.     static void PrintMatrix(int[,] matrix)
  6.     {
  7.         for (int row = 0; row < matrix.GetLength(0); row++)
  8.         {
  9.             for (int col = 0; col < matrix.GetLength(1); col++)
  10.             {
  11.                 Console.Write("{0,4}",matrix[row,col]);
  12.             }
  13.             Console.WriteLine();
  14.             Console.WriteLine();
  15.         }
  16.     }
  17.     static void Main()
  18.     {
  19.         int n = int.Parse(Console.ReadLine());
  20.         int[,] myMatrix = new int[n,n];
  21.         int counter = 1;
  22.         for (int col = 0; col < n; col++)
  23.         {
  24.             for (int row = 0; row < n; row++)
  25.             {
  26.                 myMatrix[row, col] = counter;
  27.                 counter++;
  28.                 // matrix[i, j] = i + 1 + size*j;  
  29.             }
  30.         }
  31.         PrintMatrix(myMatrix);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement