Golang : Find biggest/largest number in array
Just a quick tutorial on how to find the biggest value in a given array. Nothing fancy, just a simple for loop to find the next biggest value in the array and replace the final value ( which is the variable max ) with the biggest value is can find.
Here's the code
package main
import "fmt"
func main() {
arr := []uint{
28, 33, 16,
7, 5, 88,
}
max := arr[0] // assume first value is the smallest
for _, value := range arr {
if value > max {
max = value // found another smaller value, replace previous value in max
}
}
fmt.Println("The biggest/largest value is : ", max)
}
Output :
The biggest/largest value is : 88
Hope this simple tutorial can be useful to you. Cheers!
See also : Golang : Find smallest number in array
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+10.8k Golang : Convert a rune to unicode style string \u
+6.5k Golang : Command line ticker to show work in progress
+5.2k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+16.2k Golang : How to remove certain lines from a file
+14k Golang : rune literal not terminated error
+25.3k Golang : Force your program to run with root permissions
+4.9k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+8.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+19.8k Golang : For loop continue,break and range
+5.6k Unix/Linux : How to get own IP address ?
+18.5k Golang : Append content to a file
+42.6k Golang : Use wildcard patterns with filepath.Glob() example