Sort by

recency

|

5141 Discussions

|

  • + 0 comments

    Using Rust

    fn staircase(n: i32) {
        for i in 0..n{
            for j in 1..n-i {
                print!{" "};
            }
            for j in n-i-1..n {
                print!{"#"};
            }
            println!();
        }
    }
    
  • + 0 comments

    my solution :

    public static void staircase(int n) {

    for(int i=1;i<=n;i++){
        //increment i at every loop (ex:first loop 6-1 = 5 spaces for the first '#')
        for(int j=1;j<=n-i;j++){ 
                System.out.print(" ");
        }
    
        //print #
        for(int k= 1;k<=i;k++){
             System.out.print("#");
        }
    
        //move to next line 
         System.out.println();
    }
    
    }
    
  • + 0 comments

    python

    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
    function staircase(n: number): void {
      let ctree = ""
      let step = 0;
      const total = n * n + n
      const mod = n + 1
      for (let id = 0; id < total; id++) { 
        const i = id % mod;
        const d = total - id;
        const f = d % mod;
        if (i === 0) {
          if (step) {
            ctree += "\n"
          }
          step++
        } else if (f > step) { 
          ctree += " "
        }  else {
          ctree += "#"
        }
      }
      console.info(ctree)
    }
    
  • + 0 comments

    KOTLIN

    fun staircase(n: Int): Unit {
        // Write your code here
        for (i in 0..<n) {
            var printSharp = n - i - 1
            for (j in 0..<n) {
                if (j >= printSharp) {
                    print("#")
                } else {
                    print(" ")
                }
            }
            println();
        }
    }