75.8k views
3 votes
Write a C++ program which displays the following shape.
Please help me out with it.

Write a C++ program which displays the following shape. Please help me out with it-example-1
User Afenster
by
5.2k points

1 Answer

5 votes

Answer:

/*

Notably, this leaves a blank line at the top, so if that shouldn't be there you can tweak it.

This was built successfully with gcc

gcc -Wall shape.cpp -lstdc++

*/

#include <iostream>

using namespace std;

int main(void){

int w, x;

for(w = 0; w < 16; w += 2){

for(x = 0; x < w >> 1; x++){

cout << "*";

}

for(x = w; x < 14; x++){

cout << " ";

}

for(x = 0; x < w >> 1; x++){

cout << "*";

}

cout << endl;

}

return 1;

}

User Sheats
by
5.2k points