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 if
s, I realized maybe I should just draw it literally.
#include <stdio.h>
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?