Staircase


Problem Statement :


Staircase detail:
    This is a staircase of size n = 4:


   #
  ##
 ###
####

Its base and height are both equal to n. It is drawn using # symbols and spaces. The last line is not preceded by any spaces.

Write a program that prints a staircase of size n.

Function Description:
           Complete the staircase function in the editor below.

staircase has the following parameter(s):
    int n: an integer

Print:
    Print a staircase as described above.

Input Format:
    A single integer, n , denoting the size of the staircase.

Constraints:
   0 < n <= 100.

Output Format:
    Print a staircase of size n using # symbols and spaces.

Note: The last line must have 0 spaces in it. 

.



Solution :


                        In C :

void staircase(int n) {
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n-i-1;j++)
        {
            printf(" ");
        }

        for(int k = i; k >= 0; k--)
        {
            printf("#");
        }

        printf("\n");
    }

}




#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {

    int n;
    cin >> n;
    string str(n, ' ');
        
    for (int i = 1; i <= n; ++i) {
        str[n-i] = '#';
        cout << str << endl;
    }
    return 0;
}




In Python3 :

n=int(input())
m=" "
t=1
while n>n-n:
    print((n-1)*m+t*("#"))
    n=n-1
    t=t+1


In Java :

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

 
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		for(int i=1;i<=N;i++) {
			for(int j=1;j<=N-i;j++){
				System.out.print(" ");
			}
			for(int k=0;k<i;k++)
			System.out.print("#");
			
			System.out.println();
			
		}
		
	}

}