sylviapsh

Hourglass

Dec 26th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2. class Hourglass
  3. {
  4.   static void Main()
  5.   {
  6.     //Telerik Academy
  7.     //Once upon a time a powerful wizard was born. His name was Gwenogfryn and soon he became a great sorcerer. Kind-hearted he was. He would only use his magic to protect humans from the evil witches that would come at night. Gwenogfryn, however was a pacifist and did not want to fight or hurt the witches, so he came up with another solution. He would catch the witches and throw them into a sand-glass (the only prison a witch cannot escape from). Unfortunately, he is running out of sand-glasses. Help Gwenogfryn catch all witches by making your own sand-glasses.
  8.     //You have an integer number N (always odd number) showing the height of the sand clock.
  9.  
  10.     byte number = byte.Parse(Console.ReadLine());
  11.  
  12.     byte dots, stars;
  13.  
  14.     dots = 0;
  15.     stars = number;
  16.     bool flag = false;
  17.  
  18.     for (int row = 1; row <= number; row++)
  19.     {
  20.       for (int column = 1; column <= dots / 2; column++)
  21.       {
  22.         Console.Write(".");
  23.       }
  24.       for (int column = 1; column <= stars; column++)
  25.       {
  26.         Console.Write("*");
  27.       }
  28.       for (int column = 1; column <= dots/2; column++)
  29.       {
  30.         Console.Write(".");
  31.       }
  32.       Console.WriteLine();
  33.      
  34.       //Check if it is time to reverse the triangle to make it look like an hourglass.
  35.       if (stars == 1)
  36.       {
  37.         flag = true;
  38.       }
  39.       if (flag == true)
  40.       {
  41.         stars += 2;
  42.         dots -= 2;
  43.       }
  44.       else
  45.       {
  46.         stars -= 2;
  47.         dots += 2;
  48.       }
  49.     }
  50.   }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment