Skip to content

Instantly share code, notes, and snippets.

@willbailey
Created December 9, 2012 04:56
Show Gist options
  • Save willbailey/4243382 to your computer and use it in GitHub Desktop.
Save willbailey/4243382 to your computer and use it in GitHub Desktop.
Twelve Days of Christmas
#include <stdio.h>
int main(int argc, char *argv[]) {
char *days[] = {"first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"};
char *gifts[] = {"a partridge in a pear tree", "two turtle doves",
"three french hens", "four calling birds", "***** five golden rings *****",
"six geese a laying", "seven swans a swimming", "eight maids a milking",
"nine ladies dancing", "ten lords a leaping", "eleven pipers piping",
"twelve drummers drumming"
};
int bird_gift_count = 0;
for (int i = 1; i < 13; i++) {
printf("\nOn the %s day of Christmas my true love gave to me,\n", days[i - 1]);
for (int ii = i; ii > 0; ii--) {
if (ii == 0 && i > 0) printf("and ");
printf("%s \n", gifts[ii - 1]);
if (ii < 8 && ii != 5) bird_gift_count += ii;
}
}
// better stock up on birdseed my love
printf("\ntotal birds received: %i\n", bird_gift_count);
return 0;
}
@tobie
Copy link

tobie commented Dec 10, 2012

In C? Really!?

@willbailey
Copy link
Author

It's for a Christmas Card. I was going for a retro look.

@willbailey
Copy link
Author

Maybe I should've done it in FORTRAN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment