Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CircleNumbers
- {
- static void Main()
- {
- start:
- Console.Write("n = ");
- int n = int.Parse(Console.ReadLine());
- if (n <= 0 || n > 20)
- {
- Console.WriteLine("Error! N must be in range 1-20");
- goto start;
- }
- Console.Clear();
- int MinCol=0;
- int MaxCol=(n*4)-4;
- int MinRow=0;
- int MaxRow = n-1;
- int row = 0;
- int col = 0;
- for (int i = 1; i <= n * n; )
- {
- if (row == MinRow && col <= MaxCol)
- {
- for (col = MinCol; col <= MaxCol; col = col +4)
- {
- Console.SetCursorPosition(col, row);
- Console.Write(i);
- i++;
- }
- MinRow++;
- col = MaxCol;
- }
- if (col == MaxCol && row < MaxRow)
- {
- for (row = MinRow; row <= MaxRow; row++)
- {
- Console.SetCursorPosition(col, row);
- Console.Write(i);
- i++;
- }
- MaxCol = MaxCol - 4;
- row = MaxRow;
- }
- if (row == MaxRow && col > MaxCol)
- {
- for (col = MaxCol; col >= MinCol; col = col - 4)
- {
- Console.SetCursorPosition(col, row);
- Console.Write(i);
- i++;
- }
- MaxRow--;
- col = MinCol;
- }
- if (col == MinCol && row > MaxRow)
- {
- for (row = MaxRow; row >= MinRow; row--)
- {
- Console.SetCursorPosition(col, row);
- Console.Write(i);
- i++;
- }
- MinCol = MinCol + 4;
- row = MinRow;
- }
- }
- Console.SetCursorPosition(1, (n * 2) + 2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment