Advertisement
RMarK0

Untitled

Dec 27th, 2019
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. namespace ConsoleApp10
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             const int n = 8, m = 5;
  8.             double[,] massiv = new double[n, m];
  9.             int strok = m;
  10.             int stolb = n;
  11.             int sum = strok * stolb;
  12.             int stolb1 = 0; // указатели для массива
  13.             int strok1 = 0; // указатели для массива
  14.             int Count = 1;
  15.             while (stolb > 0)
  16.             {
  17.                 for (int y = 0; y < 4; y++)
  18.                 {
  19.                     for (int x = 0; x < ((strok < stolb) ? stolb : strok); x++) // strok stolb что больше, столько лимит
  20.                     {
  21.                         if (y == 0 && x < strok - strok1 && Count <= sum)                 // вправо
  22.                             massiv[y + stolb1, x + strok1] = Count++;                     // x < чего-либо - ограничение, чтоб ниче лишнего не вписать
  23.  
  24.                         if (y == 1 && x < stolb - stolb1 && x != 0 && Count <= sum)       // вниз
  25.                             massiv[x + stolb1, strok - 1] = Count++;
  26.  
  27.                         if (y == 2 && x < strok - strok1 && x != 0 && Count <= sum)       // влево
  28.                             massiv[stolb - 1, strok - (x + 1)] = Count++;
  29.  
  30.                         if (y == 3 && x < stolb - (stolb1 + 1) && x != 0 && Count <= sum) // вверх
  31.                             massiv[stolb - (x + 1), stolb1] = Count++;
  32.  
  33.                     }
  34.                 }
  35.                 stolb--; //
  36.                 strok--; // осталось
  37.                 stolb1 += 1; //
  38.                 strok1 += 1; // заняли
  39.             }
  40.  
  41.             for (int i = 0; i < n; i++)
  42.             {
  43.                 for (int j = 0; j < m; j++)
  44.                     Console.Write("{0,5}", massiv[i, j]);
  45.                 Console.WriteLine();
  46.             }
  47.             Console.ReadKey();
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement