Skip to content

Instantly share code, notes, and snippets.

@chrisswong
Created February 26, 2015 14:52
Show Gist options
  • Save chrisswong/ba83aa78f92bfd2cf322 to your computer and use it in GitHub Desktop.
Save chrisswong/ba83aa78f92bfd2cf322 to your computer and use it in GitHub Desktop.
FizzBuzz Test in Obj-C (Recursion)
printFizzBallWithNumber(1 , 100);
void printFizzBallWithNumber(int startNumber, int endNumber) {
if (startNumber <= endNumber) {
int i = startNumber;
//
if ( i % 3 == 0 || i % 5 == 0 ) {
if (i % 3 == 0 && i % 5 == 0 ) {
NSLog(@"FizzBuzz");
}
else {
if (i % 3 == 0) {
NSLog(@"Fizz");
}
if (i % 5 == 0) {
NSLog(@"Buzz");
}
}
} else {
NSLog(@"%d\n", i);
}
startNumber++;
printFizzBallWithNumber( startNumber , endNumber);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment