← Back to Loops
Question 293
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 exactly what is shown in Expected Output. Use the Euclidean algorithm in a loop: repeatedly replace(a, b)with(b, a % b)untilbis0.
Expected Output:
12= newline. No newline after the last line.
Hints4 available
Sign in to use hintsTopics:
Loops
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.