Advertisement
dim4o

Loops_09_MatrixOfNumbers

Mar 26th, 2014
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. static void Main()
  2.         {
  3.             int num = int.Parse(Console.ReadLine());
  4.             if (num > 0 && num < 21)
  5.             {
  6.                 Console.Clear();
  7.                 int[,] matrix = new int[num, num];
  8.                 for (int row = 0; row < num; row++)
  9.                 {
  10.                     for (int col = 0; col < num; col++)
  11.                     {
  12.                         if (row > 0)
  13.                         {
  14.                             matrix[row, col] = matrix[row - 1, col] + 1;
  15.                         }
  16.                         else
  17.                         {
  18.                             matrix[row, col] = col + 1;
  19.                         }
  20.                         Console.SetCursorPosition(row*3, col*2);
  21.                         Console.Write(matrix[row, col]);
  22.                     }
  23.                     Console.WriteLine();
  24.                 }
  25.             }
  26.             else
  27.             {
  28.                 Console.WriteLine("out of range");
  29.             }
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement