staafl

problem 3 - hourglass

Mar 30th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. int height = int.Parse(Console.ReadLine());
  9. int lowerRow = 0;
  10. for (int i = 0; i < height; i++)
  11. {
  12. // height = 7
  13. if (i < height / 2 + 1)
  14. {
  15. // upper half of hourglass
  16. Console.Write(new string('.', i));
  17. Console.Write(new string('*', height - 2 * i));
  18. Console.Write(new string('.', i));
  19. // 0, 1, ... height / 2
  20. }
  21. else
  22. {
  23. lowerRow++; // 1,2,3...
  24. Console.Write(new string('.', height / 2 - lowerRow));
  25. Console.Write(new string('*', 1 + lowerRow * 2));
  26. Console.Write(new string('.', height / 2 - lowerRow));
  27. // height / 2 - 1, height / 2 - 2... 0
  28. }
  29. Console.WriteLine();
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment