31ph4n70m

Maximum_of_array.go

Nov 28th, 2019
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.78 KB | None | 0 0
  1. // golang solution to codeabbey challenge 15
  2. package main
  3. import (
  4.     "bufio"
  5.     "fmt"
  6.     "os"
  7.     "strings"
  8.     "strconv"
  9. )
  10.  
  11. func MinMax(array []int) (int, int) {
  12.     var max int = array[0]
  13.     var min int = array[0]
  14.     for _, value := range array {
  15.         if max < value {
  16.             max = value
  17.         }
  18.         if min > value {
  19.             min = value
  20.         }
  21.     }
  22.     return max, min
  23. }
  24.  
  25. func main(){
  26.     reader := bufio.NewReader(os.Stdin)
  27.     text, _ := reader.ReadString('\n')
  28.     strnums := strings.Split(text, " ")
  29.     nums := []int{}
  30.    
  31.     for _, i := range strnums {
  32.         j, err := strconv.Atoi(i)
  33.         if err != nil {
  34.             panic(err)
  35.         }
  36.         nums = append(nums, j)
  37.     }
  38.    
  39.     res1, res2 := MinMax(nums)
  40.     fmt.Println(res1, res2)
  41. }
Add Comment
Please, Sign In to add comment