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
+17.6k Golang : How to tell if a file is compressed either gzip or zip ?
+11k Golang : Command line file upload program to server example
+11.6k Golang : Concatenate (combine) buffer data example
+5.4k PHP : See installed compiled-in-modules
+30.5k Golang : How to redirect to new page with net/http?
+10.2k Golang : Test a slice of integers for odd and even numbers
+13.3k Golang : Convert(cast) int to int64
+24.3k Golang : Upload to S3 with official aws-sdk-go package
+4.5k Linux/MacOSX : Search and delete files by extension
+15k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+15.8k Golang : Force download file example