Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Go by Example with struct, method and euclid
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