@nakov/

nested-for-loops-draw-rhombus-csharp

C#

Draw a rhombus using nested for-loops 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.6559219147625779","path":"main.cs","file":{"path":"main.cs","content":{"asEncoding":{"base64":"dXNpbmcgU3lzdGVtOwoKY2xhc3MgRHJhd1Job21idXNOZXN0ZWRMb29wcyB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpIHsgICAgICAgIAogICAgICAgIGludCBuID0gMTA7CiAgICAgICAgZm9yIChpbnQgcm93ID0gMTsgcm93IDwgbjsgcm93KyspCiAgICAgICAgewogICAgICAgICAgICB2YXIgc3BhY2VzID0gTWF0aC5BYnMobiAvIDIgLSByb3cpOwogICAgICAgICAgICB2YXIgc3RhcnMgPSBuLzIgLSBzcGFjZXM7CiAgICAgICAgICAgIGZvciAoaW50IGNvbCA9IDE7IGNvbCA8PSBzcGFjZXM7IGNvbCsrKQogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZSgiICIpOwogICAgICAgICAgICBmb3IgKGludCBjb2wgPSAxOyBjb2wgPD0gc3RhcnM7IGNvbCsrKQogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZSgiKiAiKTsKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoKTsKICAgICAgICB9CiAgICB9Cn0K"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System;

class DrawRhombusNestedLoops {
    public static void Main() {        
        int n = 10;
        for (int row = 1; row < n; row++)
        {
            var spaces = Math.Abs(n / 2 - row);
            var stars = n/2 - spaces;
            for (int col = 1; col <= spaces; col++)
                Console.Write(" ");
            for (int col = 1; col <= stars; col++)
                Console.Write("* ");
            Console.WriteLine();
        }
    }
}