โ Back to Loops
Question 340
GCD with a Loop
GCD with a Loop
Read two positive integersaandbfrom input. Use a loop (the Euclidean algorithm) to compute their greatest common divisor, and print it followed by a newline. For input12 18the exact output is: 6 Repeata % b, movingbintoaand the remainder intob, untilbbecomes 0.
Expected Output:
6
Topics:
Loops
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.