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.
- Prepare
- Algorithms
- Warmup
- Staircase
- Discussions
Staircase
Staircase
Sort by
recency
|
5185 Discussions
|
Please Login in order to post a comment
Console output is misleading. If you start by printing # and then print ##. The console will look like this: -## -# And not like this: -# -##
I know the point is "The order in which they show up". I still feel it's not a great idea to show that to beginners
void staircase(int n) { for(int i = 1; i <= n; i++) { int k = i; for(int j = n; j > 0; j--) { if(j > k) { cout << " "; } else { cout << "#"; k--; } } cout << endl; } }
my solution in java
if(n<1 || n>100) return; for (int i = 1; i<= n; i++) { for (int j = 0; j < n-i; j++) { System.out.print(" "); } for (int k = 0; k < i ; k++) { System.out.print("#"); } System.out.println(); }