We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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);
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Staircase
You are viewing a single comment's thread. Return to all 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.