Recursion

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(17, 13)

What is the result?

  • A

    1

    check_circle
  • B

    17

  • C

    13

  • D

    0

Explanation

17 and 13 are both prime; their gcd is 1.

Want 10 more like this — adaptive to your weak spots?

Related questions