Advertisement
Venciity

[ Telerik C#] Primitives And Variables - EX 9

Feb 13th, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. // 9. Write a program that prints an isosceles triangle of 9 copyright symbols ©.
  2. // Use Windows Character Map to find the Unicode code of the © symbol. Note: the © symbol may be displayed incorrectly.
  3. using System;
  4. using System.Text; // We must use this library so we can use the ENCODING property
  5.  
  6. namespace _09_CopyRightTriangle
  7. {
  8.     class CopyRightTriangle
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             // The main idea behind this solution is to find the count of blank and filled cells in every row.
  13.             // Then create an string and Print it.
  14.             Console.OutputEncoding = Encoding.Unicode;
  15.  
  16.             Console.WriteLine("Do you want to create a triangle?");
  17.             Console.Write("Please enter the row count: ");
  18.             int rows = Int32.Parse(Console.ReadLine()); // This is the ammount of rows that we must print
  19.             Console.Write("Now Enter the Symbol that you want to use: ");
  20.             char symbol = char.Parse(Console.ReadLine());
  21.  
  22.             int cells = (rows * 2 - 1);
  23.             int symbolIncrement = 1;
  24.             int blankCount; // брояч за празен брой
  25.             int symbolCount; // брояч за симболите
  26.  
  27.             Console.WriteLine("Triangle made of {0}",symbol);
  28.             for (int r = 0; r < rows; r++)
  29.             {
  30.                 blankCount = cells - symbolIncrement; // Total Blank cells on the row [ брояч за празен брой = клетки - символното увеличение]
  31.                 symbolCount = cells - blankCount;     // Total Symbol cells on the row [брояч за симболите = клетки - брояч за празен брой]
  32.  
  33.                 string blankCells = new string(' ', blankCount / 2); // We Divide by 2 the total ammount of blank cells so the triangle is centered in the middle
  34.                 string fullCells = new string(symbol,symbolCount);
  35.  
  36.                 Console.Write("{0}{1}", blankCells, fullCells); // We Print the blank and the full cells at once. The right side of the triangle is not fulled with blank characters but it can be if you wish: Console.Write("{0}{1}{0}", blank, full, blank);
  37.  
  38.                 symbolIncrement = symbolIncrement + 2; // The count of the symbols used in every next row is increased by 2
  39.                 Console.WriteLine(); // New line / Row
  40.             }
  41.             Console.ReadLine();
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement