Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp10
- {
- class Program
- {
- static void Main(string[] args)
- {
- const int n = 8, m = 5;
- double[,] massiv = new double[n, m];
- int strok = m;
- int stolb = n;
- int sum = strok * stolb;
- int stolb1 = 0; // указатели для массива
- int strok1 = 0; // указатели для массива
- int Count = 1;
- while (stolb > 0)
- {
- for (int y = 0; y < 4; y++)
- {
- for (int x = 0; x < ((strok < stolb) ? stolb : strok); x++) // strok stolb что больше, столько лимит
- {
- if (y == 0 && x < strok - strok1 && Count <= sum) // вправо
- massiv[y + stolb1, x + strok1] = Count++; // x < чего-либо - ограничение, чтоб ниче лишнего не вписать
- if (y == 1 && x < stolb - stolb1 && x != 0 && Count <= sum) // вниз
- massiv[x + stolb1, strok - 1] = Count++;
- if (y == 2 && x < strok - strok1 && x != 0 && Count <= sum) // влево
- massiv[stolb - 1, strok - (x + 1)] = Count++;
- if (y == 3 && x < stolb - (stolb1 + 1) && x != 0 && Count <= sum) // вверх
- massiv[stolb - (x + 1), stolb1] = Count++;
- }
- }
- stolb--; //
- strok--; // осталось
- stolb1 += 1; //
- strok1 += 1; // заняли
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- Console.Write("{0,5}", massiv[i, j]);
- Console.WriteLine();
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement