Java gcd gcd(int a, int b)

Here you can find the source of gcd(int a, int b)

Description

gcd

License

Open Source License

Declaration

public static int gcd(int a, int b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int gcd(int a, int b) {
        while (b > 0) {
            int tmp = b;
            b = a % b;//from w w  w  . ja va2s  . c  o  m
            a = tmp;
        }
        return a;
    }

    public static int gcd(int[] ia) {
        int r = ia[0];
        for (int i = 1; i < ia.length; i++) {
            r = gcd(r, ia[i]);
        }
        return r;
    }
}

Related

  1. gcd(int a, int b)
  2. gcd(int a, int b)
  3. gcd(int a, int b)
  4. gcd(int a, int b)
  5. gcd(int a, int b)
  6. gcd(int a, int b)
  7. gcd(int a, int b, int... rest)
  8. gcd(int firstNumber, int secondNumber)
  9. gcd(int k, int m)