Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Exercise14Spiral
- {
- static void Main()
- {
- int input = int.Parse(Console.ReadLine());
- int x = (input - 1) * 4;
- int y = 0;
- int direction = 2;
- int number = input;
- Console.Clear();
- for (int i = 0; i < input; i++)
- {
- Console.SetCursorPosition(4 * i, 0);
- Console.WriteLine(i + 1);
- }
- while (input > 0)
- {
- for (int a = 0; a < 2; a++)
- {
- for (int i = 0; i < input - 1; i++)
- {
- switch (direction)
- {
- case 1: x += 4; break;
- case 2: y += 2; break;
- case 3: x -= 4; break;
- case 4: y -= 2; break;
- }
- number++;
- Console.SetCursorPosition(x, y);
- Console.WriteLine(number);
- }
- direction++;
- if (direction > 4)
- {
- direction = 1;
- }
- }
- input--;
- }
- Console.SetCursorPosition(0, 42);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement