Add code
This commit is contained in:
parent
f95cd273d3
commit
0c63b698be
2 changed files with 26 additions and 0 deletions
2
3-map-in-go/Makefile
Normal file
2
3-map-in-go/Makefile
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
all:
|
||||||
|
go run main.go
|
24
3-map-in-go/main.go
Normal file
24
3-map-in-go/main.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var a [10]int
|
||||||
|
|
||||||
|
for i := range a {
|
||||||
|
a[i] = i
|
||||||
|
}
|
||||||
|
|
||||||
|
var b [10]struct{n int; nn int}
|
||||||
|
|
||||||
|
for i, n := range a {
|
||||||
|
b[i].n = n
|
||||||
|
b[i].nn = n * n
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range b {
|
||||||
|
fmt.Printf("%v: %v\n", v.n, v.nn)
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue