Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Hourglass
- {
- static void Main()
- {
- //Telerik Academy
- //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.
- //You have an integer number N (always odd number) showing the height of the sand clock.
- byte number = byte.Parse(Console.ReadLine());
- byte dots, stars;
- dots = 0;
- stars = number;
- bool flag = false;
- for (int row = 1; row <= number; row++)
- {
- for (int column = 1; column <= dots / 2; column++)
- {
- Console.Write(".");
- }
- for (int column = 1; column <= stars; column++)
- {
- Console.Write("*");
- }
- for (int column = 1; column <= dots/2; column++)
- {
- Console.Write(".");
- }
- Console.WriteLine();
- //Check if it is time to reverse the triangle to make it look like an hourglass.
- if (stars == 1)
- {
- flag = true;
- }
- if (flag == true)
- {
- stars += 2;
- dots -= 2;
- }
- else
- {
- stars -= 2;
- dots += 2;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment