Created
September 12, 2017 14:08
-
-
Save thinkphp/0677b4493bf86e371676e8ce9741ddf4 to your computer and use it in GitHub Desktop.
Go by Example with struct, method and euclid
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" | |
type Pair struct { | |
a, b int | |
} | |
func (n *Pair) euclid() int { | |
for n.b != 0 { | |
n.a, n.b = n.b, n.a % n.b | |
} | |
return n.a | |
} | |
func main() { | |
a := 10 | |
b := 4 | |
c := 10 | |
d := 3 | |
r := Pair{a,b} | |
f := Pair{c,d} | |
fmt.Printf("GDC<%d,%d> = %d\n", a, b, r.euclid()) | |
fmt.Printf("GDC<%d,%d> = %d\n", c, d, f.euclid()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment