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
+7.2k Golang : HTTP Server Example
+13.4k Golang : package is not in GOROOT during compilation
+8k Golang : Serving HTTP and Websocket from different ports in a program example
+11.8k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+14.1k Golang : How do I get the local IP (non-loopback) address ?
+4.8k Unix/Linux : How to open tar.gz file ?
+12.8k Golang : How to check if your program is running in a terminal
+5.1k Golang : Extract XML attribute data with attr field tag example
+4.5k Golang : Frobnicate or tweaking a string example
+9.9k Golang : How to determine a prime number?
+14.2k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+25.8k Golang : Convert CSV data to JSON format and save to file