Advertisement
Guest User

Isosceles Triangle - Two Mirror Sides

a guest
Apr 10th, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. public class IsoscelesTriangleThree
  7. {
  8.     public static void Main()
  9.     {
  10.         Console.OutputEncoding = Encoding.Unicode;
  11.         char unicode = '\u00A9';
  12.         int b = 6;
  13.         int c = 0;
  14.         // The halfTriangle list will be storing the first half of our isosceles triangle
  15.         List<string> halfTriangle = new List<string>();
  16.  
  17.         // will be storing the half of the hypotenuse
  18.         StringBuilder line = new StringBuilder();
  19.  
  20.         // calculates all strings necessary for one cathetus of the triangle
  21.         // stores them in the halfTriangle list
  22.         do
  23.         {
  24.             string space1 = new String(' ', b);
  25.             string print = space1 + unicode;
  26.             halfTriangle.Add(print);
  27.             b = b - 1;
  28.         } while (b != 0);
  29.  
  30.         // builds a string for a half-hypotenuse
  31.         do
  32.         {
  33.             line.Append(unicode);
  34.             c = c + 1;
  35.         }
  36.         while (c != 7);
  37.  
  38.         // storing this half-hypotenuse into the halfTriangle list
  39.         halfTriangle.Add(line.ToString());
  40.  
  41.         // printing the left half of the triangle
  42.         foreach (string str in halfTriangle)
  43.         {
  44.             Console.WriteLine(str);
  45.         }
  46.  
  47.         // printing the right half of the triangle as a mirror image of the left one
  48.         for (int i = 0; i < halfTriangle.Count; i++)
  49.         {
  50.             Console.SetCursorPosition(6, i);
  51.  
  52.             var temp = halfTriangle[i].Reverse();
  53.  
  54.             Console.WriteLine("{0, 7}", string.Join("", temp));
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement