Sort by

recency

|

5088 Discussions

|

  • + 0 comments

    Here is my c++ implementation, you can watch the video here : https://youtu.be/4yntFcMY30U

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main()
    {
        int n;
        cin >> n;
        for(int i = 1; i <= n; i++) {
            string s(n-i, ' '), e(i, '#');
            cout << s + e << endl;
        }
    
        return 0;
    }
    
  • + 0 comments

    def staircase(n): for i in range(1,n+1): print(' ' * (n - i) + '#' * i) if name == 'main': n = int(input().strip())

    staircase(n)
    
  • + 0 comments

    In pyhton

       for idx in range(n):
           print((n-(idx+1))*' '+(idx+1)*'#')
    
  • + 0 comments

    My code in golang:

    func staircase(n int32) {
        new := int(n)
        for i := 1; i <= new; i++{
            for j := 0; j < new - i; j++{
                fmt.Printf(" ")
            }
            for k := 0; k < i; k++{
                fmt.Printf("#")
            }
            fmt.Println()
        }
    }
    
  • + 0 comments

    My logic was: For each line print "n - t" spaces and "t #" and plus "t". But my code was a little bit different.

        public static void staircase(int n) {
            int tmp = n - 1;
            while(tmp >= 0){
                for(int i = 0; i < n; ++i) {
                    System.out.print(i < tmp ? " " : "#");
                }
               
                System.out.println();
                --tmp;
            }
        }