DonJabone

CircleNumbers

May 28th, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4.  
  5. class CircleNumbers
  6. {
  7.     static void Main()
  8.     {
  9.         start:
  10.         Console.Write("n = ");
  11.         int n = int.Parse(Console.ReadLine());
  12.         if (n <= 0 || n > 20)
  13.         {
  14.             Console.WriteLine("Error! N must be in range 1-20");
  15.             goto start;
  16.         }
  17.         Console.Clear();
  18.         int MinCol=0;
  19.         int MaxCol=(n*4)-4;
  20.         int MinRow=0;
  21.         int MaxRow = n-1;
  22.         int row = 0;
  23.         int col = 0;
  24.         for (int i = 1; i <= n * n; )
  25.         {
  26.             if (row == MinRow && col <= MaxCol)
  27.             {
  28.                 for (col = MinCol; col <= MaxCol; col = col +4)
  29.                 {
  30.                     Console.SetCursorPosition(col, row);
  31.                     Console.Write(i);
  32.                     i++;
  33.                 }
  34.                 MinRow++;
  35.                 col = MaxCol;
  36.             }
  37.             if (col == MaxCol && row < MaxRow)
  38.             {
  39.                 for (row = MinRow; row <= MaxRow; row++)
  40.                 {
  41.                     Console.SetCursorPosition(col, row);
  42.                     Console.Write(i);
  43.                     i++;
  44.                 }
  45.                 MaxCol = MaxCol - 4;
  46.                 row = MaxRow;
  47.             }
  48.             if (row == MaxRow && col > MaxCol)
  49.             {
  50.                 for (col = MaxCol; col >= MinCol; col = col - 4)
  51.                 {
  52.                     Console.SetCursorPosition(col, row);
  53.                     Console.Write(i);
  54.                     i++;
  55.                 }
  56.                 MaxRow--;
  57.                 col = MinCol;
  58.             }
  59.             if (col == MinCol && row > MaxRow)
  60.             {
  61.                 for (row = MaxRow; row >= MinRow; row--)
  62.                 {
  63.                     Console.SetCursorPosition(col, row);
  64.                     Console.Write(i);
  65.                     i++;
  66.                 }
  67.                 MinCol = MinCol + 4;
  68.                 row = MinRow;
  69.             }
  70.         }
  71.         Console.SetCursorPosition(1, (n * 2) + 2);
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment