Created
February 14, 2016 01:34
-
-
Save itolosa/f274efab5415569fc4f7 to your computer and use it in GitHub Desktop.
My first recursion in Objective-C
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
// | |
// main.m | |
// | |
// Created by Ignacio Tolosa on 2/13/16. | |
// Copyright © 2016 PasajesLA. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface MyMathClass : NSObject | |
-(int) factorial: (int) n; | |
@end | |
@implementation MyMathClass | |
-(int) factorial: (int) n | |
{ | |
return n > 1 ? [self factorial: n-1] * n : 1; | |
} | |
@end | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
MyMathClass *m = [[MyMathClass alloc] init]; | |
for (int i = 0; i < 10; i++) { | |
NSLog(@"Factorial de %d es %d\n", i, [m factorial: i]); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment