Sort by

recency

|

5185 Discussions

|

  • + 0 comments
    def staircase(n):
        for i in range(1, n + 1):
            str = " " * (n - i) + "#" * i
            print(str)
    
  • + 0 comments
    #include <alloca.h>
    void staircase(int n) {
        char *str = alloca(n+1);
        memset(str, ' ', n);
        str[n] = 0;
        
        for (char *ptr = str+n-1; ptr >= str; ptr--) {
            *ptr = '#';
            puts(str);
        }
    }
    
  • + 0 comments

    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

  • + 0 comments

    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; } }

  • + 0 comments

    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(); }