Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program that prints an isosceles triangle of 9 copyright symbols Β©.
- * Note that the Β© symbol may be displayed incorrectly at the console so you may need
- * to change the console character encoding to UTF-8 and assign a Unicode-friendly font
- * in the console. Note also, that under old versions of Windows the Β© symbol
- * may still be displayed incorrectly, regardless of how much effort you put to fix it. */
- namespace _8.IsoscelesTriangle
- {
- using System;
- using System.Text;
- public class DrawIsoscelesTriangle
- {
- public static void Main(string[] args)
- {
- Console.OutputEncoding = Encoding.UTF8;
- char copySymb = '\u00A9';
- int countRows = 4;
- Console.WriteLine("The Isosceles Triangle with 9 copyright symbols '{0}' is:", copySymb);
- Console.WriteLine();
- // Print the first top row of Triangle:
- string spaceBeforeSymbol = new string(' ', countRows - 1);
- Console.WriteLine(spaceBeforeSymbol + copySymb);
- // Print next rows below:
- for (int row = 1; row < countRows - 1; row++)
- {
- PrintNextRowOfTriangle(countRows, row, copySymb);
- }
- // Print the last bottom row of Triangle:
- for (int i = 0; i < countRows; i++)
- {
- Console.Write(copySymb + " ");
- }
- Console.WriteLine();
- Console.WriteLine();
- }
- private static void PrintNextRowOfTriangle(int countRows, int row, char symbol)
- {
- // Calculate lenght of whole current row:
- int lenght = countRows + row;
- // Calculate whitespace before First copyright symbol:
- int countSpacesBeforeFirstSymbol = (countRows - 1) - row;
- string spaceBeforeFirstSymbol = new string(' ', countSpacesBeforeFirstSymbol);
- // Calculate whitespace between left and right copyright symbols on the row:
- int countMiddleSpaces = (lenght - countSpacesBeforeFirstSymbol) - 2;
- string middleSpace = new string(' ', countMiddleSpaces);
- // Print whole current row:
- Console.WriteLine(spaceBeforeFirstSymbol + symbol + middleSpace + symbol);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement