Created
December 29, 2018 23:17
-
-
Save williamhaley/6679f5cdc8f48ab819e984a5b70687c5 to your computer and use it in GitHub Desktop.
Calculate the Greatest Common Denominator using GoLang
This file contains 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" | |
) | |
// https://www.reddit.com/r/golang/comments/7b4mt9/greatest_common_divisor/ | |
// GreatestCommonDenominator finds the GCD of two ints | |
func GreatestCommonDenominator(a, b int) int { | |
remainder := 0 | |
for b != 0 { | |
remainder = a % b | |
a, b, remainder = b, remainder, a | |
} | |
return a | |
} | |
func main() { | |
fmt.Println(GreatestCommonDenominator(0, 128)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment