Skip to content

Instantly share code, notes, and snippets.

@morontt
Created July 1, 2014 07:13
Show Gist options
  • Select an option

  • Save morontt/ebd5b46a299182125aa2 to your computer and use it in GitHub Desktop.

Select an option

Save morontt/ebd5b46a299182125aa2 to your computer and use it in GitHub Desktop.
Greatest Common Divisor (Euclidean algorithm)
package main
import "fmt"
func euc(m, n uint32) uint32 {
var res uint32
r := m % n
if r == 0 {
res = n
} else {
res = euc(n, r)
}
return res
}
func main() {
var (
m uint32
n uint32
)
fmt.Print("Enter m: ")
fmt.Scanln(&m)
fmt.Print("Enter n: ")
fmt.Scanln(&n)
z := euc(m, n)
fmt.Println("Result: ", z)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment