(Drawing Patterns with Nested for Loops) Write a program that uses for statements to print the following patterns separately, one below the other. Use for loops to generate the patterns. All asterisks (*) should be printed by a single statement of the form cout << '*'; (this causes the asterisks to print side by side). [Hint: The last two patterns require that each line begin with an ap- propriate number of blanks. Extra credit: Combine your code from the four separate problems into a single program that prints all four patterns side by side by making clever use of nested for loops.]
What will be an ideal response?
Extra-credit solution that prints the triangles side by side:
```
// Create triangles of asterisks side-by-side using nested for loops
#include
using namespace std;
int main()
{
int row; // the row position
int column; // the column position
int space; // number of spaces to print
// print one row at a time, tabbing between triangles
for ( row = 1; row <= 10; row++ )
{
// first triangle
for ( column = 1; column <= row; column++ )
cout << "*";
for ( space = 1; space <= 10 - row; space++ )
cout << " ";
cout << "\t";
// second triangle
for ( column = 10; column >= row; column-- )
cout << "*";
for ( space = 1; space < row; space++ )
cout << " ";
cout << "\t";
// third triangle
for ( space = 1; space < row; space++ )
cout << " ";
for ( column = 10; column >= row; column-- )38 cout << "*";
cout << "\t";
// fourth triangle
for ( space = 10; space > row; space-- )
cout << " ";
for ( column = 1; column <= row; column++ )
cout << "*";
cout << endl;
} // end for
} // end main
```
You might also like to view...
What do we call a visual effect in which the edge of an image-usually an oval-gradually fades away?
A. frame B. ovoid C. feather D. vignette
When the taskbar groups windows for the same program on a single button, you can view mini-windows or live ________ previews of each open file
Fill in the blank(s) with correct word
A(n) ________ letter is created in a main document
Fill in the blank(s) with correct word
The ________ prefix is used to refer to fields in a recordset
Fill in the blank(s) with correct word