Drawing Diamonds

September 9, 2014

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.

Pages: 1 2