[Golang] Greatest Common Divisor via Euclidean Algorithm


Compute the greatest common divisor (GCD) via Euclidean algorithm in Go programming language.

Run Code on Go Playground

// greatest common divisor (GCD) via Euclidean algorithm
func GCD(a, b int) int {
      for b != 0 {
              t := b
              b = a % b
              a = t
      }
      return a
}

Tested on:


References:

[1]Euclidean algorithm - Wikipedia
[2]Basic and Extended Euclidean algorithms - GeeksforGeeks