Uncategorized

Drawing Diamonds

For my developers and web designers, can you crack the code?

Drawing Diamonds

Given a small positive integer n, write a function that draws a diamond, either filled or in outline as specified by the user. For instance, here are filled and outline diamonds for n = 5:

*              *

* *           * *

* * *         *   *

* * * *      *       *

* * * * *    *         *

* * * *        *     *

* * *           *   *

* *             * *

*                *

Note that there is a single space between asterisks in the filled version of the diamond.

Your task is to write a program that draws diamonds as described above. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Loading…

Advertisements
Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s