Sort by

recency

|

5090 Discussions

|

  • + 0 comments

    public static void staircase(int n) {

        for(int i=0;i<n;i++){
            for(int j=n-1;j>=0;j--){
                System.out.print(i<j?" ":"#");
            }
            System.out.println();
        }
    }
    

    }

  • + 0 comments
    // My code in C
    void staircase(int n) {
        for(int i = 0; i < n; i++)
        {
            for(int j = n - 1 - i; j > 0; j--)
            {
                printf(" ");
            }
            for(int k = n - i - 1; k < n; k++)
            {
                printf("#");
            }
            printf("\n");
        }
        return;
    }
    
  • + 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)*'#')