Use for loops to construct a program that displays a pyramid of Xs on the screen. The
pyramid should look like this
X
XXX
XXXXX
XXXXXXX
XXXXXXXXX
except that it should be 20 lines high, instead of the 5 lines shown here. One way to do this is to
nest two inner loops, one to print spaces and one to print Xs, inside an outer loop that steps
down the screen from line to line.
1
Expert's answer
2013-04-17T10:03:55-0400
#include <iostream> using namespace std; void main() { for (int i= 0; i < 20; i++) // for i = 0 to i < 20 { for(int j = 0; j <= i; j++) // for j = 0 to j <= i { cout<< "X"; // print X } cout<< endl; // print end of line } }
Comments
Leave a comment