public class App {
public static int gcd(int[] a) {
int c = 0; // variable de maximo comun divisor
for (int i = 1; i <= a[0]; i++) {
int x = 0;
for (int k = 0; k < a.length; k++) {
if (a[k] % i == 0) {
x++;
if (x == a.length) {
c = i;
} // if todos los números tienen a ese número como divisor se le asigna ese número
// a c
} // if es divisor se suma
} // for k
} // for i
return c;
} // metodo para sacar el maximo comun divisor de x numeros
public static void main(String[] args) {
int[] a = { 30, 60, 120, 700 }; // numeros a los que se le saca el maximo comun divisor
System.out.println(gcd(a));
} // main
}
0 Comments