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
+9.6k Golang : List available AWS regions
+7.2k Linux : How to fix Brother HL-1110 printing blank page problem
+35.4k Golang : Integer is between a range
+5.7k Cash Flow : 50 days to pay your credit card debt
+10.2k Golang : Convert file unix timestamp to UTC time example
+11.6k Golang : How to detect a server/machine network interface capabilities?
+16.9k Golang : How to save log messages to file?
+18.8k Golang : Padding data for encryption and un-padding data for decryption
+17.9k Golang : Check if a directory exist or not
+29.2k Golang : Saving(serializing) and reading file with GOB
+7.4k Gogland : Single File versus Go Application Run Configurations
+5k Golang : Convert lines of string into list for delete and insert operation