Last active
June 19, 2017 13:07
-
-
Save hsinewu/b3e415371bd990094bac03aa3052cf78 to your computer and use it in GitHub Desktop.
read integers from stdin to array
This file contains hidden or 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
1 2 3 |
This file contains hidden or 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" | |
) | |
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) | |
} | |
} |
This file contains hidden or 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
Hi 1 | |
Hi 2 | |
Hi 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment