Created
July 1, 2014 07:13
-
-
Save morontt/ebd5b46a299182125aa2 to your computer and use it in GitHub Desktop.
Greatest Common Divisor (Euclidean algorithm)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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