Advertisement
Masovski

08. Isosceles Triangle

Mar 11th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2.  
  3.     class IsoscelesTriangle
  4.     {
  5.         static void Main()
  6.         {
  7.             Console.OutputEncoding = System.Text.Encoding.UTF8;
  8.             byte triangleHeight;
  9.             char copyrightSymbol = '\x00a9';
  10.             char spaceSymbol = ' ';
  11.             byte innerSpacesCount = 1;
  12.             Console.Write("Height of Triangle (0-254): ");
  13.             bool bCorrectHeight = byte.TryParse(Console.ReadLine(), out triangleHeight);
  14.             if (bCorrectHeight)
  15.             {
  16.                 for (int row = 1; row <= triangleHeight; row++)
  17.                 {
  18.                     int leftSpacesCount = triangleHeight - row;
  19.                    
  20.                     Console.Write(new string(spaceSymbol, leftSpacesCount));
  21.                     Console.Write(new string(copyrightSymbol, 1));
  22.                     if (row > 2)
  23.                     {
  24.                         innerSpacesCount += 2;
  25.                     }
  26.                     if (row != 1 && row != triangleHeight)
  27.                     {
  28.                         Console.Write(new string(spaceSymbol, innerSpacesCount));
  29.                         Console.Write(new string(copyrightSymbol, 1));
  30.                     }
  31.                     else if (row == triangleHeight)
  32.                     {
  33.                         for (int i = triangleHeight; i > 1; i--)
  34.                         {
  35.                             Console.Write(new string(spaceSymbol, 1));
  36.                             Console.Write(new string(copyrightSymbol, 1));
  37.                         }
  38.                     }
  39.                    
  40.                     Console.WriteLine();
  41.                 }    
  42.             }
  43.             else
  44.             {
  45.                 Console.WriteLine("Please enter correct height - a number between 0 and 255.");
  46.             }
  47.         }
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement