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
+8.7k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+13.1k Golang : Recombine chunked files example
+17.1k Golang : Implement getters and setters
+4.6k How to check with curl if my website or the asset is gzipped ?
+6.9k Golang : Gomobile init produce "iphoneos" cannot be located error
+9.1k Golang : Convert file content to Hex
+4.5k Clean up Visual Studio For Mac installation failed disk full problem
+4.2k Python : Create Whois client or function example
+16.1k Golang : Qt image viewer example
+24.6k Mac/Linux and Golang : Fix bind: address already in use error
+5k Golang : Extract unicode string from another unicode string example
+13.3k Golang : Parsing or breaking down URL