Multiple choice

Let Gcd (m,n) be a recursively defined function as given below Gcd (n,m) m<n Gcd (m,n) = m n=0 Gcd(n,m%n) otherwise Gcd (6,15) = ?

  1. 6

  2. 15

  3. 3

  4. 0

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Gcd(6, 15): Since 6 < 15, it calls Gcd(15, 6). Then Gcd(15, 6) calls Gcd(6, 15%6) = Gcd(6, 3). Then Gcd(6, 3) calls Gcd(3, 6%3) = Gcd(3, 0). Since n=0, it returns m=3.