Merry Cumulative Song Exercise

In my C programming books, I often use the directions on a shampoo bottle as an example of basic programming:

1. Lather.
2. Rinse.
3. Repeat.

Another real-life example of programming techniques happens in music. Specifically, cumulative songs are representative of loops. This type of song includes 99 Bottles of Beer and the holiday favorite, The Twelve Days of Christmas.

A cumulative song has repetitive lyrics. They’re fun to sing, but do get tiresome after a while. I believe I last sang the full rendition of The Twelve Days of Christmas when I was 8-years-old. (That’s not counting singing along with Alan Sherman’s famous parody. And even he doesn’t repeat every lyric.)

This month’s Exercise is to write code that spits out the lyrics for The Twelve Days of Christmas. And I’d like you to do more than simply write several dozen printf() statements: The code must include a loop that outputs the lyrics.

As a refresher, click here to view the lyrics, as well as see the output of my solution to the Exercise.

Please try this exercise on your own before you peek at my solution.

Leave a Reply