Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Spiral
- {
- static void Main()
- {
- byte n = byte.Parse(Console.ReadLine());
- int count = 1;
- int row = 1;
- int col = 0;
- int stopper = n;
- int stopperCol = 0;
- int stopperRow = 3;
- int special = n;
- for (int k = 0; k < n; k++)
- {
- for (int i = 0; i < n * n; i++)
- {
- if (i < stopper)
- {
- Console.Write("{0,4}", count);
- count++;
- }
- if ((i >= stopper) && ((i - stopper) < (stopper - 1)))
- {
- row += 2;
- col = special * 4 - 4;
- Console.SetCursorPosition(col, row);
- Console.Write("{0,4}", count);
- count++;
- }
- if ((i - stopper) >= stopper - 1 && col > stopperCol)
- {
- col -= 4;
- Console.SetCursorPosition(col, row);
- Console.Write("{0,4}", count);
- count++;
- }
- if (col == stopperCol && row > stopperRow)
- {
- row -= 2;
- Console.SetCursorPosition(col, row);
- Console.Write("{0,4}", count);
- count++;
- }
- }
- stopper -= 2;
- stopperCol += 4;
- stopperRow += 2;
- special--;
- }
- Console.SetCursorPosition(0, n * 2 + 2);
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement