We are going to find the hackerrank solutions of algorithms section and trying to solve the staircase hackerrank solution in c with full code and logic explanation. In this solution, we are also going to add the output of the code so that our reader can understand that our staircase hackerrank solution is working fine and solutions are updated timely.

So we a hackerrank programming problem statement below let dive to find the solution. Our challenge is to find the Staircase Program in C Hackerrank So let's Do it. First, we have understood the problem statement then only we can write code in our desire programming language.

Consider a staircase of size n=4:

Complete the staircase function in the editor below. It should print a staircase as described above.

the staircase has the following parameter(s):

A single integer,n, denoting the size of the staircase.

0< n <= 100

Print a staircase of size

Note: The last line must have

6

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

Staircase Program in C Hackerrank there is no logic we have to just print the pattern in a staircase by using the hash (#) symbol. we always use stairs in our daily life now turn to implement in programming life. See the below pattern this is called a staircase. When asking for the user to enter the number that means the height of the staircase. In this case, I am taking

## Staircase Problem Statement

Consider a staircase of size n=4:

#

##

###

####

Observe that its base and height are both equal to

Write a program that prints a staircase of size

**n**, and the image 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. It should print a staircase as described above.

the staircase has the following parameter(s):

- n: an integer

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

#### Sample Input

6

#### Sample Output

#

##

###

####

#####

######

#### Explanation

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

**n = 6**.

## Staircase Hackerrank Solution Logic

Staircase Program in C Hackerrank there is no logic we have to just print the pattern in a staircase by using the hash (#) symbol. we always use stairs in our daily life now turn to implement in programming life. See the below pattern this is called a staircase. When asking for the user to enter the number that means the height of the staircase. In this case, I am taking

**Height = 10**.

### Staircase Program in C Hackerrank

#

##

###

####

#####

######

#######

########

#########

##########

**Submit your solution here:-**Click here

Tip:-Before copy the solution I recommended please read this full article, this will help you to build your own logic.

## Staircase Hackerrank Solution in C

#include<stdio.h>

int main()

{

int n, i, j, s = 0, pattern = 0;

scanf("%d", &n);

/*

No of rows of pattern

*/

for(i = 0; i < n; i++)

{

s = n - (i+1);

for(j = 0; j < s; j++)

{

printf(" ");

}

/*We are going to print no. of space minus 1 each time */

pattern = i + 1;

for(j = 0; j < pattern; j++)

{

printf("#");

}

/*

Printing the Hash("#") pattern

*/

printf("\n");

}

}

how is it possible

ReplyDeleteWhy it's not possible, here simply firstly we are leaving space less the input number and increasing a loop by one and also decreasing a space count by one and print the symbol two time and so on. It's easy to try again I am sure you will catch the logic easy.

DeleteThanks

Thank you very much.

ReplyDeleteI managed to modify my code quoting your logic.

However, I don't understand logic for the space part.

s = n - (i+1)

so in your code for space

i < n

j < s

so I try to sub n with some number

if n = 1, i = 0, j = 0;

n = 2, i = 1, j = 0;

n = 3, i = 2, j = 0;

etc

so i is representing column?

j is always 0, does this line of code

s = n - (i+1);

for(j = 0; j < s; j++)

necessary?

I am a beginner.

Thank you very much for your help.

My I know what's wrong with this logic?? I am stuck. Please help

ReplyDeletefor(int i=0;in-1)

cout<<"#";

else cout<<" ";

}

cout<<endl;

}