CJCoding With Joseph
15free / daySign inCreate account

GCD of Two Numbers

Read two positive integers a and b from standard input and print their greatest common divisor (GCD), with no trailing newline. For example, for the input 48 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) until b is 0.

Expected Output:

12

= newline. No newline after the last line.

Hints4 available
Topics:
Loops
📥 Auto-Input:
48 36
This input is automatically fed to your program's stdin
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.