Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- func main() {
- x := []int{ // array of numbers of type int
- // just random numbers
- 85, 89, 65, 45, 32,
- 1, 21, 32, 56, 66,
- 98, 12, 99, 97, 55,
- }
- // 0th index of x array is 85
- smlNumber := x[0] // assuming first value is the smallest
- // smlNumber goin to hold the numbers and print the smallest one
- for i := 0; i < len(x); i++ { // iterate over the x
- if x[i] < smlNumber {
- smlNumber = x[i] // if smaller value is found replace it with the previous one
- }
- }
- fmt.Println("smallest number is: ", smlNumber) // smlest number is: 1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement