FRom hackerrank

Consider a staircase of size :
   #
  ##
 ###
####
Solution in C# -

class Solution {

    static void staircase(int n) {

        for(int i=1; i<=n; i++)
        {
            for(int j=i; j<n; j++)
            Console.Write(" ");
            for(int j=1; j<=i; j++)
                Console.Write("#");
            Console.WriteLine();
        }

    }

    static void Main(string[] args) {
        int n = Convert.ToInt32(Console.ReadLine());

        staircase(n);
    }
}

Post a Comment

Previous Post Next Post