Advertisement
g-stoyanov

Exercise14Spiral

Dec 2nd, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2.  
  3. class Exercise14Spiral
  4. {
  5.     static void Main()
  6.     {
  7.         int input = int.Parse(Console.ReadLine());
  8.         int x = (input - 1) * 4;
  9.         int y = 0;
  10.         int direction = 2;
  11.         int number = input;
  12.         Console.Clear();
  13.         for (int i = 0; i < input; i++)
  14.         {
  15.             Console.SetCursorPosition(4 * i, 0);
  16.             Console.WriteLine(i + 1);
  17.         }
  18.         while (input > 0)
  19.         {
  20.             for (int a = 0; a < 2; a++)
  21.             {
  22.                 for (int i = 0; i < input - 1; i++)
  23.                 {
  24.                     switch (direction)
  25.                     {
  26.                         case 1: x += 4; break;
  27.                         case 2: y += 2; break;
  28.                         case 3: x -= 4; break;
  29.                         case 4: y -= 2; break;
  30.                     }
  31.                     number++;
  32.                     Console.SetCursorPosition(x, y);
  33.                     Console.WriteLine(number);
  34.                 }
  35.                 direction++;
  36.                 if (direction > 4)
  37.                 {
  38.                     direction = 1;
  39.                 }
  40.             }
  41.             input--;
  42.         }
  43.         Console.SetCursorPosition(0, 42);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement