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.1k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+9.9k Golang : Characters limiter example
+8.4k Golang : Get all countries currencies code in JSON format
+26k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+18.6k Golang : Set or Add HTTP Request Headers
+21.6k Golang : Calculate time different
+29.7k Golang : Get local IP and MAC address
+5.2k Golang : Process non-XML/JSON formatted ASCII text file example
+13.9k Golang : Find location by IP address and display with Google Map
+9.5k Swift : Convert (cast) String to Integer
+10.7k Golang : Perform sanity checks on filename example
+8k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases