64 609
Assignments Done
99,1%
Successfully Done
In September 2018

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
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;
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions