Advertisement
sashomaga

Fir Tree

Dec 24th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using System;
  2. //Input
  3. //The input data should be read from the console.
  4. //On the only input line you have an integer number N, showing the height of the tree.
  5. //The input data will always be valid and in the format described. There is no need to check it explicitly.
  6. //Output
  7. //The output data should be printed on the console.
  8. //You must print the fir tree on the console. Each row contains only characters "." (point)  or "*" (asterisk).
  9. //The first row should have exactly one "*" in the middle (that is the top of the tree) and each of the next lines two more.
  10. //The last line should have exactly one asterisk in the middle, showing the stem of the tree.
  11. class Program
  12. {
  13.     static void Main()
  14.     {
  15.         int hight = int.Parse(Console.ReadLine());
  16.         int length = 1;
  17.         for (int i = 2; i < hight; i++)
  18.         {
  19.             length += 2;
  20.         }
  21.         //Console.WriteLine(length);
  22.         for (int j = 1; j <= length; j += 2)
  23.         {
  24.  
  25.             for (int i = 1; i <= (length - j) / 2; i++)
  26.             {
  27.                 Console.Write(".");
  28.             }
  29.             for (int i = 1; i <= j; i++)
  30.             {
  31.                 Console.Write("*");
  32.             }
  33.             for (int i = 1; i <= (length - j) / 2; i++)
  34.             {
  35.                 Console.Write(".");
  36.             }
  37.             Console.WriteLine();
  38.         }
  39.         //last row
  40.         for (int i = 1; i <= length / 2; i++)
  41.         {
  42.             Console.Write(".");
  43.         }        
  44.             Console.Write("*");
  45.         for (int i = 1; i <= length/ 2; i++)
  46.         {
  47.             Console.Write(".");
  48.         }
  49.         Console.WriteLine();
  50.            
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement