Printing multiple different shapes on the same line Whilst scanning my C programming textbook, I saw this practice problem from a very early chapter:



I got to thinking that the problem probably wants you to draw each shape separately, which would be very easy.

But to do literally what the question asks (print them on the same line), I couldn't see any easy way! The rectangle is 9x9, but they seem 5 spaces apart, the oval is 7 wide, the arrow tip is 5x3, etc. Maybe if the arrow had tips on both ends, I could dissect the whole picture horizontally.

After dabbling with ways to produce the rectangle, oval, arrow, and diamond by themselves, and then to somehow print each row correctly with loops and ifs, I realized maybe I should just draw it literally.

#include &lt;stdio.h&gt;

int main() {

    puts("*********       ***         *           *");
    puts("*       *      *   *       ***         * *");
    puts("*       *     *     *     *****       *   *");
    puts("*       *     *     *       *        *     *");
    puts("*       *     *     *       *       *       *");
    puts("*       *     *     *       *        *     *");
    puts("*       *     *     *       *         *   *");
    puts("*       *      *   *        *          * *");
    puts("*********       ***         *           *");

    return 0;

}


I could have put it all in one puts with newlines but I found that was pretty unreadable.

Is there any better way to do this? Am I completely missing something / am I doing it in the most efficient way?
It really is that simple.  Your idea of putting everything into one puts() call would be an improvement, because I/O calls are relatively expensive.  Not that it really matters in this exercise.  It's just a good habit.

The second shape should be a little bit wider. =)

Note that a return 0; at the end of main() is automatically implied, as a special case.

#include &lt;stdio.h&gt;

int main() {

    puts("*********        ***          *           *\n"
         "*       *      *     *       ***         * *\n"
         "*       *     *       *     *****       *   *\n"
         "*       *     *       *       *        *     *\n"
         "*       *     *       *       *       *       *\n"
         "*       *     *       *       *        *     *\n"
         "*       *     *       *       *         *   *\n"
         "*       *      *     *        *          * *\n"
         "*********        ***          *           *");

    return 0;

}