Answer to Question #17372 in C++ for Yasser

Question #17372
Write a program using two nested loops to draw the following shape
*
***
*****
*******
*****
***
*
1
Expert's answer
2012-10-26T11:12:37-0400
#include <cmath>

#include <iostream>

#include<conio.h>

using namespace std;

int main()

{

for (int i = 4; i >= -4; i--)

{

int absVal = abs(i);

int count = 1 + (4 - absVal) * 2;

cout << " ";




for (int j = 0; j < absVal; j++)

{

cout << " ";

}




for (int k = 0; k < count; k++)

{

cout << "*";

}




cout << endl;

}




_getch();

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

Assignment Expert
29.10.12, 14:26

You're welcome. We are glad to be helpful. If you really liked our service please press like-button beside answer field. Thank you!

Yasser
26.10.12, 20:07

thank you

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS