I'm trying to write a simple program which asks for 5 numbers and outputs their GCD. I've already discovered how to do this with two numbers with a simple method:
private static int gcd(int number1, int number2) //Finds GCD of 2 numbers.
{
if(number2 == 0)
{
return number1;
}
return gcd(number2, number1%number2);
}
The actual math in the return statement is what confuses me though and I'm not sure how I would write that out with 5 or even more numbers. I've heard that doing this method recursively such as with "gcd(a,b,c)=gcd(gcd(a,b),c)" is the best method, but I guess I'm having trouble with the actual logic of the math in question. I just need a good starting point, really, with how to return 3 numbers, then 4, then 5, etc. I think once I get the logic portion down I'll understand how to do this much easier.