psotirov

Sand-Glass

Dec 10th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2.  
  3. class SandGlass
  4. {
  5.     static void Main()
  6.     {
  7.         int N = int.Parse(Console.ReadLine());
  8.         int limit = N;
  9.         int factor = -2;
  10.         string fullLine = new string('*', N); // first (and last) line
  11.         Console.WriteLine(fullLine);
  12.         N -= 2;
  13.         while (N < limit) // when N == limit that is the time for the last line
  14.         {
  15.             string emptySpaces = new string('.', (limit - N)/2); // creates empty spaces '.' in both ends
  16.             Console.WriteLine(emptySpaces + new string('*', N) + emptySpaces); // prints the current line
  17.             if (N < 3) factor = 2; // if single (or double) '*' is reached it is time to change direction - '*''s must grow now on
  18.             N += factor; // calculates next value
  19.         }
  20.         Console.WriteLine(fullLine); // last line
  21.  
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment