Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // golang solution to codeabbey challenge 15
- package main
- import (
- "bufio"
- "fmt"
- "os"
- "strings"
- "strconv"
- )
- func MinMax(array []int) (int, int) {
- var max int = array[0]
- var min int = array[0]
- for _, value := range array {
- if max < value {
- max = value
- }
- if min > value {
- min = value
- }
- }
- return max, min
- }
- func main(){
- reader := bufio.NewReader(os.Stdin)
- text, _ := reader.ReadString('\n')
- strnums := strings.Split(text, " ")
- nums := []int{}
- for _, i := range strnums {
- j, err := strconv.Atoi(i)
- if err != nil {
- panic(err)
- }
- nums = append(nums, j)
- }
- res1, res2 := MinMax(nums)
- fmt.Println(res1, res2)
- }
Add Comment
Please, Sign In to add comment