Sort by

recency

|

5212 Discussions

|

  • + 0 comments

    Python3:

    def staircase(n):
        for x in range(1, n + 1):
            print(("#"*x).rjust(n))
    
  • + 0 comments

    In C++ we can use string constructor and solve this

    void staircase(int n) {
        for( int i = 1; i<=n; i++)
        {
            cout<<string(n-i, ' ')<<string(i, '#')<<endl;
        }
    }
    
  • + 0 comments

    C++

    void staircase(int n) {
    string hash = "#";
    for (int i = 0; i < n; i++, hash += "#") {
        for (int j = n-i; j > 1; j--) {
            cout << " ";
        }
        cout << hash << endl;
        }
    }
    
  • + 0 comments
    public static void staircase(int n) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i+j >= n-1) {
                    System.out.print("#");
                } else {
                    System.out.print(" ");
                }
            }
            System.out.println("");
        }
    }
    
  • + 0 comments

    JAVA CODE: ` public static void staircase(int n) {

        int padding = 0;
        int elem = 0;
        for(int i = 1; i <= n; i++) {
            padding = n - i;
            elem = n - padding;
            if(padding > 0) System.out.format("%" + padding + "s", "");
            do {
                System.out.print("#");
                elem--;
            } while(elem > 0);
            System.out.println();
        }
    
    }
    

    `