GCD of Two Numbers

Published by Matt in

Write a function that returns the greatest common divisor (GCD) of two integers.

Examples

gcd(32, 8) ➞ 8

gcd(8, 12) ➞ 4

gcd(17, 13) ➞ 1

Notes

  • Both values will be positive.
  • The GCD is the largest factor that divides both numbers.
Watch a quick demo on how Edabit works.