sylviapsh

Fir Tree

Dec 26th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. class FirTree
  3. {
  4.   static void Main()
  5.   {
  6.     //Telerik Academy
  7.     //Christmas Eve is coming so even programmers got to prepare!
  8.     //In the spirit of the event your task is to write a program that prints a fir tree to the console.
  9.     //On the only input line you have an integer number N, showing the height of the tree.
  10.  
  11.     int n = int.Parse(Console.ReadLine());
  12.  
  13.     int stars = 1;
  14.     int dots = 2*n - 3;
  15.     int dots1;
  16.     int dots2;
  17.     int starsCycle = stars;
  18.     dots1 = dots2 = dots/2;
  19.  
  20.     for (int row = 1; row < n; row++)
  21.     {
  22.       while (dots1 > 0)
  23.       {
  24.         Console.Write(".");
  25.         dots1--;
  26.       }
  27.       while (starsCycle > 0)
  28.       {
  29.         Console.Write("*");
  30.         starsCycle--;
  31.       }
  32.       while (dots2 > 0)
  33.       {
  34.         Console.Write(".");
  35.         dots2--;
  36.       }
  37.       Console.WriteLine("");
  38.         dots -= 2;
  39.         stars += 2;
  40.         dots1 = dots2 = (dots / 2);
  41.         starsCycle = stars;
  42.     }
  43.  
  44.     stars = 1;
  45.     dots = 2 * n - 3;
  46.     starsCycle = stars;
  47.     dots1 = dots2 = dots / 2;
  48.     for (int row = 1; row == 1; row++)
  49.     {
  50.       while (dots1 > 0)
  51.       {
  52.         Console.Write(".");
  53.         dots1--;
  54.       }
  55.       while (starsCycle > 0)
  56.       {
  57.         Console.Write("*");
  58.         starsCycle--;
  59.       }
  60.       while (dots2 > 0)
  61.       {
  62.         Console.Write(".");
  63.         dots2--;
  64.       }
  65.       Console.WriteLine("");
  66.     }
  67.  
  68.   }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment