• + 0 comments

    My solution in C# builds the staircase row by row. For each row i (from 1 to n):

    I print (n - i) spaces to align it to the right

    Then I print i hash symbols (#)

    This way the output grows step by step until the full staircase is printed.

        public static void staircase(int n)
    {
        for(int i =1; i <= n; i++){
            int spaces = n - i;
            int hashtags = i;
            string staircase = new string(' ', spaces) + new string('#', hashtags);
            Console.WriteLine(staircase);
        }
    }