Created
December 14, 2016 18:38
-
-
Save johnwesonga/1b93f7d09e6aa02b6844bef0596b6fce to your computer and use it in GitHub Desktop.
Read ints with whitespaces from stdin
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 main() { | |
fmt.Println(`Enter the number of integers`) | |
var n int | |
if m, err := fmt.Scan(&n); m != 1 { | |
panic(err) | |
} | |
fmt.Println(`Enter the integers`) | |
all := make([]int, n) | |
ReadN(all, 0, n) | |
fmt.Println(all) | |
} | |
func ReadN(all []int, i, n int) { | |
if n == 0 { | |
return | |
} | |
if m, err := fmt.Scan(&all[i]); m != 1 { | |
panic(err) | |
} | |
ReadN(all, i+1, n-1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment