Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main(string[] args)
- {
- int height = int.Parse(Console.ReadLine());
- int lowerRow = 0;
- for (int i = 0; i < height; i++)
- {
- // height = 7
- if (i < height / 2 + 1)
- {
- // upper half of hourglass
- Console.Write(new string('.', i));
- Console.Write(new string('*', height - 2 * i));
- Console.Write(new string('.', i));
- // 0, 1, ... height / 2
- }
- else
- {
- lowerRow++; // 1,2,3...
- Console.Write(new string('.', height / 2 - lowerRow));
- Console.Write(new string('*', 1 + lowerRow * 2));
- Console.Write(new string('.', height / 2 - lowerRow));
- // height / 2 - 1, height / 2 - 2... 0
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment