Skip to content

Instantly share code, notes, and snippets.

@shailrshah
Last active October 10, 2017 17:20
Show Gist options
  • Save shailrshah/2e6b3cf4ee8fea1f281d3154779b8dbc to your computer and use it in GitHub Desktop.
Save shailrshah/2e6b3cf4ee8fea1f281d3154779b8dbc to your computer and use it in GitHub Desktop.
Calculate the GCD and LCM of two numbers
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