Skip to content

Instantly share code, notes, and snippets.

@theevo
Created March 26, 2020 15:57
Show Gist options
  • Save theevo/9c63aba6ef75aea8134943fd1808a1a0 to your computer and use it in GitHub Desktop.
Save theevo/9c63aba6ef75aea8134943fd1808a1a0 to your computer and use it in GitHub Desktop.
FizzBuzz in Objective-C
//
// 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