id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

james.shockey@austinisd.org > recursiveGCD
prev  |  next  |  chance

Recursive GCD There is a recursive algorithm for finding the greatest common divisor (GCD) of two positive integers. It states that, for any two positive integers big and small such that big >= small (if big isn't >= small, then swap them). The GCD can be calculated as follows: 1. divide big by small to get the "remainder" (remember that big must be >= small and that remainder comes from MODULUS) 2. if the remainder is zero, then the GCD = small 3. otherwise set big equal to small and set small equal to the remainder 4. repeat steps 1, 2, and 3 until the remainder is zero


recursiveGCD(12, 16) → 4
recursiveGCD(24, 12) → 12
recursiveGCD(13, 14) → 1

...Save, Compile, Run (ctrl-enter)

int recursiveGCD(int a, int b) }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Post-solution available

Copyright Nick Parlante 2017 - privacy