Answer to Question #184686 in C++ for Shuvo

Question #184686

Write a program that produces the following output using nested for loops.

****** ///////////// ****** 

***** ///////////\\ ***** 

**** /////////\\\\ **** 

*** //////\\\\\\\ *** 

** ////\\\\\\\\\ ** 

* //\\\\\\\\\\\ * 

\\\\\\\\\\\\\ 



1
Expert's answer
2021-04-23T09:19:33-0400
#include <iostream>
using namespace std;

int main() {
    const int N = 6;
    int nStar = N;
    int nSlash = 2*N;
    int nBackSlash = 0;

    for (int i=0; i<=N; i++) {
        for (int j=0; j<nStar; j++)
            cout << '*';
        if (nStar > 0)
            cout << ' ';
        for (int j=0; j<nSlash; j++)
            cout << '/';
        for (int j=0; j<nBackSlash; j++)
            cout << '\\';
        if (nStar > 0)
            cout << ' ';
        for (int j=0; j<nStar; j++)
            cout << '*';
        cout << endl;

        nStar--;
        nSlash -= 2;
        nBackSlash += 2;
    }
}

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