svetlozar_kirkov

Sand Glass

Oct 26th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2.  
  3. namespace SandGlass
  4. {
  5.     class SandGlass
  6.     {
  7.         static void Main()
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             int k = n - 2;
  11.             int m = 1;
  12.  
  13.             for (int i = 0; i < n; i++)
  14.             {
  15.                 if (i == 0 || i == n)
  16.                 {
  17.                     Console.Write(new string('*',n));
  18.                     Console.WriteLine();
  19.                 }
  20.                 else if (i > 0 && i < n/2)
  21.                 {
  22.                     Console.Write(new string('.',m));
  23.                     Console.Write(new string('*',k));
  24.                     Console.Write(new string('.',m));
  25.                     Console.WriteLine();
  26.                     m++;
  27.                     k -= 2;
  28.                 }
  29.                 else if (i == n/2)
  30.                 {
  31.                     Console.Write(new string('.',n-n/2-1));
  32.                     Console.Write(new string('*',1));
  33.                     Console.Write(new string('.',n-n/2-1));
  34.                     Console.WriteLine();
  35.                     k = n/2 - 1;
  36.                     m = 3;
  37.                 }
  38.                 else if (i > n/2 && i < n)
  39.                 {
  40.                     Console.Write(new string('.',k));
  41.                     Console.Write(new string('*',m));
  42.                     Console.Write(new string('.',k));
  43.                     Console.WriteLine();
  44.                     k--;
  45.                     m += 2;
  46.                 }
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment