lmarkov

Matrix Output

Dec 11th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. /*
  2.  * Write a program that reads from the console a positive integer number N (N < 20) and outputs a matrix
  3.  */
  4.  
  5. using System;
  6.  
  7. class MatrixOutput
  8. {
  9.     static void Main()
  10.     {
  11.         byte numberN;
  12.         string invalidInput = "Please enter a valid number 0 < N < 20!" + Environment.NewLine;
  13.         Console.WriteLine("Enter a value for N: ");
  14.         while (!(byte.TryParse(Console.ReadLine(), out numberN) && numberN > 0 && numberN < 20))
  15.         {
  16.             Console.WriteLine(invalidInput);
  17.             Console.WriteLine("Enter a value for N: ");
  18.         }
  19.         Console.WriteLine();
  20.         for (int j = 0; j < numberN; j++)
  21.         {
  22.             for (int k = 1; k <= numberN; k++)
  23.             {
  24.                 Console.Write("{0,5} ", k + j);
  25.             }
  26.             Console.WriteLine();
  27.         }        
  28.         Console.WriteLine();
  29.         Main();
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment