public static int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
// call: gcd(48, 18)What is the result?
- Acheck_circle
6
- B
3
- C
18
- D
9
Explanation
Euclidean algorithm: gcd(48,18)=gcd(18,12)=gcd(12,6)=gcd(6,0)=6.
AP Computer Science A· difficulty 3/5
public static int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
// call: gcd(48, 18)What is the result?
6
3
18
9
Explanation
Euclidean algorithm: gcd(48,18)=gcd(18,12)=gcd(12,6)=gcd(6,0)=6.
Want 10 more like this — adaptive to your weak spots?