Created
February 28, 2015 07:40
-
-
Save chrisswong/d4c44a20c711966cf293 to your computer and use it in GitHub Desktop.
Fizz Buzz Test with Objective-c with incremental number recursion
This file contains hidden or 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
printFizzBuzzWithEndNumber(100); | |
void printFizzBuzzWithEndNumber(int endNumber) { | |
if (endNumber > 1) | |
{ | |
printFizzBuzzWithEndNumber(endNumber-1); | |
} | |
// reminder > 0 = true reminder = 0 = false | |
BOOL isDividedBy3 = !(endNumber % 3); | |
BOOL isDividedBy5 = !(endNumber % 5); | |
if (isDividedBy3 || isDividedBy5) { | |
if (isDividedBy3 && isDividedBy5) { | |
NSLog(@"FizzBuzz"); | |
} | |
else { | |
if (isDividedBy3) { | |
NSLog(@"Fizz"); | |
} | |
if (isDividedBy5) { | |
NSLog(@"Buzz"); | |
} | |
} | |
} else { | |
NSLog(@"%d\n", endNumber); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment