Skip to content

Instantly share code, notes, and snippets.

@lelandjansen
Created January 8, 2016 04:09
Show Gist options
  • Save lelandjansen/1ffe53ce979abc5ae9c6 to your computer and use it in GitHub Desktop.
Save lelandjansen/1ffe53ce979abc5ae9c6 to your computer and use it in GitHub Desktop.
FizzBuzz
/*
fizzBuzz prints integers from 1 to max. For multiples of three, “Fizz” is
printed instead of the number. For multiples of five, “Buzz” is printed instead
of the number. For numbers which are multiples of both three and five,
“FizzBuzz” is printed instead of the number.
*/
#include <stdio.h>
void fizzBuzz(int max) {
if (!max) return;
for (int i = 1; i <= max; i++) {
if (i%3 == 0 && i%5 == 0) {
printf("FizzBuzz\n");
}
else if (i%3 == 0) {
printf("Fizz\n");
}
else if (i%5 == 0) {
printf("Buzz\n");
}
else {
printf("%d\n", i);
}
}
} // End of fizzBuzz
int main(int argc, const char * argv[]) {
fizzBuzz(0);
return 0;
}
// That's all folks!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment