Last active
October 10, 2017 17:20
-
-
Save shailrshah/2e6b3cf4ee8fea1f281d3154779b8dbc to your computer and use it in GitHub Desktop.
Calculate the GCD and LCM of two numbers
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
static int getGCD(int a, int b) { | |
return (a == 0 || b == 0) ? (a + b) : (getGCD(b, a % b)); | |
} | |
static int getLCM(int a, int b) { | |
return (a * b) / getGCD(a, b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment