Skip to content

Instantly share code, notes, and snippets.

@hsinewu
Last active June 19, 2017 13:07
Show Gist options
  • Save hsinewu/b3e415371bd990094bac03aa3052cf78 to your computer and use it in GitHub Desktop.
Save hsinewu/b3e415371bd990094bac03aa3052cf78 to your computer and use it in GitHub Desktop.
read integers from stdin to array
package main
import (
"fmt"
)
func ints(n int) ([]int) {
xs := make([]int, n)
for i := range xs {
fmt.Scan(&xs[i])
}
return xs
}
func main() {
xs := ints(3)
for _, x := range xs {
fmt.Printf("Hi %d\n", x)
}
}
Hi 1
Hi 2
Hi 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment