← 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 what is shown in Expected Output. Repeata % b, movingbintoaand the remainder intob, untilbbecomes 0.
Expected Output:
6= newline. The output ends with a newline — print one 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 (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.