Skip to content

Instantly share code, notes, and snippets.

@pandey-adarsh147
Created January 6, 2014 15:45
Show Gist options
  • Save pandey-adarsh147/8284695 to your computer and use it in GitHub Desktop.
Save pandey-adarsh147/8284695 to your computer and use it in GitHub Desktop.
Euclid's Algorithm for GCD
public class EuclidAlgo {
public static void main(String ...arg) {
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt();
int n = scanner.nextInt();
System.out.println("GCD: "+ gcd(m, n));
}
private static int gcd(int m, int n) {
int r = m % n;
int q = m / n;
if(r == 0) return n;
return gcd(n, r);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment