Advertisement
Lamms

SnakeMatrix

Sep 25th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _01FillTheMatrix
  8. {
  9.     class _01FillTheMatrix
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Please enter an ineger number - number of rows");
  14.            
  15.             int n = int.Parse(Console.ReadLine());
  16.             Console.WriteLine("Please enter an ineger number - number of cols");
  17.             int m = int.Parse(Console.ReadLine());
  18.             int[,] mtx = new int[n, m];
  19.             int number = 1;
  20.  
  21.            
  22.             for (int i = 0; i < mtx.GetLength(0); i++)
  23.             {
  24.                 if (i % 2 == 0)
  25.                 {
  26.                     for (int j = 0; j < mtx.GetLength(1); j++)
  27.                      {
  28.                        mtx[i, j] = number;
  29.                        number++;
  30.                     }
  31.                 }
  32.                 else
  33.                 {
  34.                     for (int j = n-1; j >=0; j--)
  35.                     {
  36.  
  37.                         mtx[i, j] = number;
  38.                         number++;
  39.                     }
  40.                    
  41.                 }
  42.  
  43.             }
  44.             Console.WriteLine("Second matrix");
  45.             for (int i = 0; i < mtx.GetLength(0); i++)
  46.             {
  47.                 for (int j = 0; j < mtx.GetLength(1); j++)
  48.                 {
  49.                    
  50.                         Console.Write("{0} ", mtx[i, j]);
  51.                    
  52.                 }
  53.                 Console.WriteLine();
  54.             }
  55.  
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement