Created
September 15, 2012 09:51
-
-
Save dblandin/3727144 to your computer and use it in GitHub Desktop.
Greatest Common Divisor(GCD) and Least Common Multiple(LCM)
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
@interface Fraction : NSObject | |
+(int) gcd: (int) num1:(int) num2; | |
+(int) lcm: (int) num1:(int) num2; | |
@end | |
@implementation Fraction | |
+(int) gcd:(int)num1:(int)num2 | |
{ | |
if (num2 == 0) { | |
return num1; | |
} | |
return [Fraction gcd:num2:num1 % num2]; | |
} | |
+(int) lcm:(int)num1:(int)num2 | |
{ | |
return abs((num1 * num2) / [Fraction gcd:num1:num2]); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment