This could seem an easy question but I cannot find a solution. I must find the gcd of n numbers.
public int getGCD(int a, int b) {
if (b == 0) { return a; }
else { return getGCD(b, a%b); }
}
This is the popular recursive way that calculates the gcd of two numbers. But if I need to get the gcd of 3, 4, 5... n numbers? I was thinking to do something like this:
public int getGCD(int[] a) {
//the code
}
There is an array of integer as parameter, but I have no idea about the code. Do you have any suggestion?