Created
January 8, 2016 04:09
-
-
Save lelandjansen/1ffe53ce979abc5ae9c6 to your computer and use it in GitHub Desktop.
FizzBuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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