kuruku

MatrixOfNumbers

May 3rd, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2.  
  3. //Write a program that reads from the console a positive integer number n (1 ≤ n ≤ 20) and prints a matrix
  4. //like in the examples below. Use two nested loops. Examples:
  5.  
  6. //  n   matrix      n       matrix      n   matrix
  7. //  2   1 2             3   1 2 3           4   1 2 3 4  
  8. //      2 3             2 3 4               2 3 4 5
  9. //                          3 4 5               3 4 5 6
  10. //                                                  4 5 6 7
  11.  
  12.     class MatrixOfNumbers
  13.     {
  14.         static void Main()
  15.         {
  16.             int n = int.Parse(Console.ReadLine());
  17.  
  18.             for (int row = 0; row < n; row++)
  19.             {
  20.                 for (int col = 1; col <= n; col++)
  21.                 {
  22.                     Console.Write("{0,-3}",col+row);
  23.                 }
  24.                 Console.WriteLine();
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment