Answer to Question #271873 in C++ for Hamda

Question #271873

Draw a empty stairs patten using nested loop in c++

1
Expert's answer
2021-11-26T17:44:42-0500
#include <iostream>
 
using namespace std;


void stairs(int n)
{
    
    for (int i = 1; i <= n; i++) {
 
       
        int k = (i % 2 != 0) ? i + 1 : i;
 
        for (int j = 0; j < k; j++)
            cout << " * ";
        cout << endl;
    }
}
 


int main()
{
    int st = 10;
    stairs(st);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS