Greatest Common Divisor Recursive Method Show all steps t
( Greatest Common Divisor - Recursive Method )
Show all steps to use the pseudo - code segment below to find the return value of the following call to recursive function GCD() . GCD(24, 56)
FUNCTION GCD(parameter a, parameter b)
IF (b == 0) THEN
result a
ELSE
result GCD(b, a MOD b)
END IF
END FUNCTION
Solution
public class Divisor {
public static void main(String[] args) {
int a=24, b=56;
System.out.println(\"GCD of 24, 56 = \"+GCD(a, b));
}
public static int GCD(int a, int b) {
if(b==0)return a;
else {
a=a%b;
return GCD(b, a);
}
}
}
