The GCD Navigator
MediumAcc. 90.3%
+25 XP 10
Shared Factors
The Greatest Common Divisor (GCD) is the largest positive integer that divides each of two or more integers without a remainder.
The Assignment
Your function receives parameters a and b.
- Use a
whileloop that continues as long asbis not 0. - In each iteration:
- Keep a temporary copy of
b. - Update
bto be the remainder ofadivided byb(a % b). - Update
ato be the temporary copy ofb.
- Keep a temporary copy of
- After
bbecomes 0, print the value ofa.
01EXAMPLE 1
Input
a=48, b=18Output
6Explanation: Divisors of 48: 1, 2, 3, 4, 6, 8, 12, 16, 24, 48. Divisors of 18: 1, 2, 3, 6, 9, 18. Greatest shared is 6.
Constraints
- Use the iterative Euclidean algorithm.
- Do not use utility libraries.
MathLoops
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
a48
b18
Expected Output
6
Click RUN to test your solution