Created
December 2, 2012 01:09
-
-
Save codelance/4186304 to your computer and use it in GitHub Desktop.
GCD
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
private static int gcd(int x, int y){ | |
if( y <= x & (x%y) == 0) | |
return y; | |
else if( x < y) | |
return gcd(y,x); | |
else | |
return gcd(y, x % y); | |
} | |
private static int iterativegcd(int x, int y) | |
{ | |
int end = 0; | |
int winner = 0; | |
if( x < y) | |
end = y; | |
else | |
end = x; | |
winner = 1; | |
for(int i = 1; i <= end; i++) | |
{ | |
if( (x%i) == 0 & (y%i) == 0 ) | |
winner = i; | |
} | |
return winner; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment