DEV Community

Cover image for Staircase Problem solution hacker rank
Anin Arafath
Anin Arafath

Posted on

5 2

Staircase Problem solution hacker rank

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, , 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.

#include <iostream>
using namespace std;

int main()
{
    int n ;
    cin >>n;

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

        for (int k = 0; k < i; k++)
        {
            cout << "#";
        }
        cout << endl;
    }

    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay