Skip to content

Instantly share code, notes, and snippets.

@pandey-adarsh147
Created January 6, 2014 15:45

Revisions

  1. pandey-adarsh147 created this gist Jan 6, 2014.
    19 changes: 19 additions & 0 deletions EuclidAlgo.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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);
    }
    }