Skip to content

Instantly share code, notes, and snippets.

@shurizzle
Created June 1, 2015 17:30
Show Gist options
  • Save shurizzle/3a35aa7ef1fb9d266f88 to your computer and use it in GitHub Desktop.
Save shurizzle/3a35aa7ef1fb9d266f88 to your computer and use it in GitHub Desktop.
FizzBuzz
#include <stdio.h>
char const * template[] = {
"%i",
"Buzz",
"Fizz",
"FizzBuzz"
};
const int __donotuseme3[] = { 2, 0, 0 };
const int __donotuseme5[] = { 1, 0, 0, 0, 0 };
#define TEMPLATE(x) (template[__donotuseme3[(x) % 3] | __donotuseme5[(x) % 5]])
int
main(void) {
int i;
for (i = 1; i <= 100; i++) {
printf(TEMPLATE(i), i);
putchar('\n');
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment