Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.  
  7. x := []int{ // array of numbers of type int
  8. // just random numbers
  9. 85, 89, 65, 45, 32,
  10. 1, 21, 32, 56, 66,
  11. 98, 12, 99, 97, 55,
  12. }
  13. // 0th index of x array is 85
  14. smlNumber := x[0] // assuming first value is the smallest
  15. // smlNumber goin to hold the numbers and print the smallest one
  16. for i := 0; i < len(x); i++ { // iterate over the x
  17.  
  18. if x[i] < smlNumber {
  19.  
  20. smlNumber = x[i] // if smaller value is found replace it with the previous one
  21. }
  22. }
  23. fmt.Println("smallest number is: ", smlNumber) // smlest number is: 1
  24.  
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement