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
1
Expert's answer
2017-02-20T11:38:14-0500
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;
}

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
APPROVED BY CLIENTS