# Answer to Question #65417 in C++ for Ashok Saw

Question #65417

. Use forloops to construct a program that displays a pyramid of Xs on the screen. The pyramid should look like this

X

XXX

XXXXX

XXXXXXX

XXXXXXXXX

X

XXX

XXXXX

XXXXXXX

XXXXXXXXX

Expert's answer

const int n = 5;

for (int i = 0; i < n; i++)

{

for (int j = 0; j < 2*i + 1; j++)

cout << "X";

cout << endl;

}

2) Solution for normal pyramide

const int n = 5;

for (int i = 0; i < n; i++)

{

for (int j = 0; j < n-i-1; j++)

cout << " ";

for (int j = 0; j < 2 * i + 1; j++)

cout << "X";

cout << endl;

}

for (int i = 0; i < n; i++)

{

for (int j = 0; j < 2*i + 1; j++)

cout << "X";

cout << endl;

}

2) Solution for normal pyramide

const int n = 5;

for (int i = 0; i < n; i++)

{

for (int j = 0; j < n-i-1; j++)

cout << " ";

for (int j = 0; j < 2 * i + 1; j++)

cout << "X";

cout << endl;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment