Advertisement
ntodorova

12_Matrix

Nov 20th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System;
  2.  
  3. /*
  4.  * 12. Write a program that reads from the console a positive integer
  5.  * number N (N < 20) and outputs a matrix.
  6.  */
  7. class Matrix
  8. {
  9.     static void Main()
  10.     {
  11.         uint n;
  12.  
  13.         Console.Write("N = ");
  14.         string strN = Console.ReadLine();
  15.  
  16.         if (!uint.TryParse(strN, out n))
  17.         {
  18.             Console.WriteLine("Invalid number: {0}", strN);
  19.         }
  20.         else
  21.         {
  22.             if (n < 20)
  23.             {
  24.                 for (int i = 1; i <= n; i++)
  25.                 {
  26.                     for (int j = i; j <= i + n - 1; j++)
  27.                     {
  28.                         Console.Write(Convert.ToString(j).PadLeft(3, ' '), j);
  29.                     }
  30.  
  31.                     Console.WriteLine();
  32.                 }
  33.             }
  34.             else
  35.             {
  36.                 Console.WriteLine("The entered number must be less than 20!");
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement