@nakov/

triangle-of-letters-csharp

C#

Print a triangle of letters using methods in C#

fork
loading
Files
  • main.cs
  • main.exe

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.9238087175887228","path":"main.cs","file":{"path":"main.cs","content":{"asEncoding":{"base64":"dXNpbmcgU3lzdGVtOwoKY2xhc3MgVHJpYW5nbGVPZkxldHRlcnMgewogICAgc3RhdGljIHZvaWQgUHJpbnRMZXR0ZXIoY2hhciBsZXR0ZXIsIGludCBjb3VudCkKICAgIHsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IGNvdW50OyBpKyspCiAgICAgICAgICAgIENvbnNvbGUuV3JpdGUobGV0dGVyICsgIiAiKTsKICAgICAgICBDb25zb2xlLldyaXRlTGluZSgpOwogICAgfQoKICAgIHN0YXRpYyB2b2lkIE1haW4oKQogICAgewogICAgICAgIGludCBjb3VudCA9IDA7CiAgICAgICAgZm9yIChjaGFyIGxldHRlciA9ICdhJzsgbGV0dGVyIDw9ICdkJzsgbGV0dGVyKyspCiAgICAgICAgICAgIFByaW50TGV0dGVyKGxldHRlciwgKytjb3VudCk7CiAgICAgICAgZm9yIChjaGFyIGxldHRlciA9ICdjJzsgbGV0dGVyID49ICdhJzsgbGV0dGVyLS0pCiAgICAgICAgICAgIFByaW50TGV0dGVyKGxldHRlciwgLS1jb3VudCk7CiAgICB9Cn0K"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System;

class TriangleOfLetters {
    static void PrintLetter(char letter, int count)
    {
        for (int i = 0; i < count; i++)
            Console.Write(letter + " ");
        Console.WriteLine();
    }

    static void Main()
    {
        int count = 0;
        for (char letter = 'a'; letter <= 'd'; letter++)
            PrintLetter(letter, ++count);
        for (char letter = 'c'; letter >= 'a'; letter--)
            PrintLetter(letter, --count);
    }
}