Question: Problem Statement from https://www.hackerrank.com/challenges/staircase/problem? Your teacher has given you the task to draw the structure of a staircase. Being an expert programmer, you decided to

Problem Statement from https://www.hackerrank.com/challenges/staircase/problem?

Your teacher has given you the task to draw the structure of a staircase. Being an expert programmer, you decided to make a program for the same. You are given the height of the staircase. You need to print a staircase as shown in the example.

Input Format

You are given an integer N depicting the height of the staircase.

Constraints 1?N?100

Output Format

Draw a staircase of height N in the format given below.

For example:

Staircase of height 6, note that last line has 0 spaces before it.

Sample Input

6 

Sample Output

 

I am wondering how you would write the pseudocode of the following source code. Please write the pseudocode of the source code and also explain the reasoning behind both the pseudocode and the source code. Example, WHILE ( i = 0 and i < n then add 1 to i), and I know there is a neat way to write things in pseudocode and then translate that to C++.

Solution(Source Code):

#include #include #include #include #include using namespace std; /*  *  * Prosen Ghosh  * American International University - Bangladesh (AIUB)  * */ int main() { int n,sp,w = 1,k; cin >> n; k = n-1; for(int i = 0; i < n; i++){ sp = k; for(int j = 0; j < sp; j++)cout << " "; for(int m = 0; m < w; m++)cout << "#"; cout << endl; k--; w++; } return 0; }

I get lost on

 sp = k; for(int j = 0; j < sp; j++)cout << " "; for(int m = 0; m < w; m++)cout << "#";
Why do we need a double for loop? Why is the programmer choosing cryptic variable names such as sp and w, I am basically lost. The source code makes no sense to me. 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!