(Diamond of Asterisks) Write a program that prints the following diamond shape. You may use output statements that print a single asterisk (*), a single blank or a single newline. Maximize your use of repetition (with nested for statements) and minimize the number of output statements.

*
***
*****
*******
*********
*******
*****
***
*

```
// Drawing a diamond shape with asterisks using nested control statements.
#include
using namespace std;

int main()
{
// top half
for ( int row = 1; row <= 5; row++ )
{
// print preceding spaces
for ( int space = 1; space <= 5 - row; space++ )
cout << ' ';

// print asterisks
for ( int asterisk = 1; asterisk <= 2 * row - 1; asterisk++ )
cout << '*';
cout << '\n';
} // end for

// bottom half
for ( int row = 4; row >= 1; row-- )
{
// print preceding spaces
for ( int space = 1; space <= 5 - row; space++ )
cout << ' ';

// print asterisks
for ( int asterisk = 1; asterisk <= 2 * row - 1; asterisk++ )
cout << '*';

cout << '\n';
} // end for

cout << endl;
} // end main
```

Computer Science & Information Technology

You might also like to view...

If you have a worksheet with quarterly data that you want to show in a PowerPoiint presentation as well as a Word document and have editing changes reflected in both, you should use:

A) copying. B) grouping. C) linking. D) embedding.

Computer Science & Information Technology

Which of the following RAID types employs two identically sized disks and creates a mirror for data redundancy purposes?

A. RAID 0 B. RAID 1 C. RAID 1+0 D. RAID 5

Computer Science & Information Technology