โ Back to Loops
Question 223
GCD of Two Numbers
GCD of Two Numbers
Read two positive integersaandbfrom standard input and print their greatest common divisor (GCD), with no trailing newline. For example, for the input48 36, the GCD is: 12 Use the Euclidean algorithm in a loop: repeatedly replace(a, b)with(b, a % b)untilbis0.
Expected Output:
12
Topics:
Loops
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (p, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.