Created
March 26, 2020 15:57
-
-
Save theevo/9c63aba6ef75aea8134943fd1808a1a0 to your computer and use it in GitHub Desktop.
FizzBuzz in Objective-C
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
// | |
// main.m | |
// Stretch Problem 4.4 - FizzBuzz ObjC | |
// | |
// Created by theevo on 3/26/20. | |
// Copyright © 2020 Theo Vora. All rights reserved. | |
// | |
/* | |
Write a method that prints the numbers from 1 to an inputed number. But for multiples of three print "Dev" instead of the number and for the multiples of five print "Mtn". For numbers which are multiples of both three and five print "DevMtn". | |
*/ | |
#import <Foundation/Foundation.h> | |
@interface PlaygroundClass : NSObject | |
+(void) fizzBuzzToNumber:(int)number; | |
@end | |
@implementation PlaygroundClass | |
+(void) fizzBuzzToNumber:(int)number{ | |
for (int i = 1; i <= number; i++) | |
{ | |
NSString *printString = @""; | |
if (i % 3 == 0 && i % 5 == 0) { | |
printString = @"DevMtn"; | |
} else if (i % 3 == 0) { | |
printString = @"Dev"; | |
} else if (i % 5 == 0) { | |
printString = @"Mtn"; | |
} | |
NSLog(@"%d %@", i, printString); | |
} | |
} | |
@end | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
int fizzBuzzNumber; | |
printf("Input a number for FizzBuzz:"); | |
scanf("%d", &fizzBuzzNumber); | |
[PlaygroundClass fizzBuzzToNumber:fizzBuzzNumber]; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment