Created
December 6, 2013 10:43
-
-
Save ykjchen/7821799 to your computer and use it in GitHub Desktop.
Fizz Buzz in C/ObjC. The console will log each number between 1 and toValue (inclusive), substituting multiples of three with "fizz", multiples of five with "buzz", and multiples of both three and five with "fizz buzz."
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
/*! | |
* The console will log each number between 1 and toValue (inclusive), | |
* substituting multiples of three with "fizz", multiples of five with "buzz", | |
* and multiples of both three and five with "fizz buzz." | |
*/ | |
void fizzBuzz(int toValue) | |
{ | |
for (int i = 1; i <= toValue; i++) { | |
BOOL isFizz = (i % 3 == 0); | |
BOOL isBuzz = (i % 5 == 0); | |
if (isFizz && isBuzz) { | |
printf("fizzbuzz"); | |
} else if (isFizz) { | |
printf("fizz"); | |
} else if (isBuzz) { | |
printf("buzz"); | |
} else { | |
printf("%i", i); | |
} | |
printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment