Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //Input
- //The input data should be read from the console.
- //You have an integer number N (always odd number) showing the height of the sand clock.
- //The input data will always be valid and in the format described. There is no need to check it explicitly.
- //Output
- //The output should be printed on the console.
- //You should print the hourglass on the console. Each row can contain only the following characters: “.” (dot) and “*” (asterisk).
- //As shown in the example: the middle row must contain only one ‘*’ and all other symbols must be “.”.
- //Every next row (up or down from the middle one) must contain the same number of ‘*’ as the previous one plus two. You should only use “.” to
- //fill-in the rows, where necessary.
- class Program
- {
- static void Main()
- {
- int height = int.Parse(Console.ReadLine());
- bool direction = true;
- for (int i = 0, reverse = height - 1; i < height; i++, reverse--) //liness
- {
- for (int j = 1; j <= height; j++) //rows
- {
- if (i > height / 2)
- {
- direction = false;
- }
- if (direction == true)
- {
- if (i >= j)
- {
- Console.Write(".");
- }
- else if (j + i > height)
- {
- Console.Write(".");
- }
- else
- {
- Console.Write("*");
- }
- }
- if (direction == false)
- {
- if (reverse >= j)
- {
- Console.Write(".");
- }
- else if (reverse + j > height)
- {
- Console.Write(".");
- }
- else
- {
- Console.Write("*");
- }
- }
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment