settingsAccountsettings
Menusettings

Q: How to print an isosceles triangle in C#?

+4 votes
I need to write a program in C# that prints an isosceles triangle (equal sides) of 9 copyright symbols © like this:

   ©
  © ©
 ©   ©
© © © ©
asked in C# category by user Jolie Ann

3 Answers

+1 vote

Check this code out:

using System;

class IsoscelesTriangle
{
    static void Main()
    {
        char a = '\u00A9';
        Console.WriteLine("   " + a + "   ");
        Console.WriteLine("  " + a + " " + a + "  ");
        Console.WriteLine(" " + a + " " + " " + " " + a +" ");
        Console.WriteLine(a + " " + a + " " + a + " " + a);
    }
}

 

answered by user sam
edited by user golearnweb
+1 vote

If you cannot see the copyright symbol (common problem) use this:

Console.OutputEncoding = Encoding.UTF8;

answered by user sam
+1 vote

Another way (more elegant code :-):

using System;
using System.Text;

class IsoscelesTriangle
{
    static void Main()
    {
        Console.OutputEncoding = Encoding.UTF8;
        char copyRight = '\u00A9';
        Console.WriteLine("{0,4}\n{0,3}{0,2}\n{0,2}{0,4}\n{0}{0,2}{0,2}{0,2}", copyRight);
    }
}

OUTPUT:

isosceles triangle in c sharp

answered by user eiorgert
edited by user golearnweb
...