Staircase HackerRank Solution in C, C++, Java, Python

Staircase detail

This is a staircase of size :

   #
  ##
 ###
####

Its base and height are both equal to . 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 .

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, , denoting the size of the staircase.

Output Format

Print a staircase of size  using # symbols and spaces.

Note: The last line must have  spaces in it.

Sample Input

6 

Sample Output

     #
    ##
   ###
  ####
 #####
######

Explanation

The staircase is right-aligned, composed of # symbols and spaces, and has a height and width of .

Staircase HackerRank Solution in C++

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;


int main(){
      int n;
      cin>>n;
      for(int i=0;i1;j--)
         { 
          cout<<' ';
         }
          for(int j=i; j>=0;j--)
          {
          cout<<"#";
          }
          cout<

Staircase HackerRank Solution in C

#include 
#include 
#include 
#include 

int main() {
    int n, i,j;
    scanf("%d", &n);
    for(i=0;i

Staircase HackerRank Solution in Python

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

Staircase HackerRank Solution 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) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        
        int i,j,k,n = sc.nextInt();
        
        for(i=0;ii;j--){
                System.out.print(" ");
            }
            for(k=0;k<=i;k++)
                System.out.print("#");
           System.out.println(); 
        }
        
    }
}

Leave a Comment