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
+6.2k Golang : Create new color from command line parameters
+32.5k Golang : Math pow(the power of x^y) example
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+9k Golang : GMail API create and send draft with simple upload attachment example
+20k Golang : Measure http.Get() execution time
+24k Golang : Use regular expression to validate domain name
+22.4k Golang : Convert seconds to minutes and remainder seconds
+22.8k Golang : Set and Get HTTP request headers example
+9.8k Golang : interface - when and where to use examples
+9.8k Golang : Format strings to SEO friendly URL example
+19.4k Golang : Get host name or domain name from IP address
+36.8k Golang : Display float in 2 decimal points and rounding up or down