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
+11.2k Golang : Characters limiter example
+13.4k Golang : reCAPTCHA example
+12k Golang : Get remaining text such as id or filename after last segment in URL path
+4.9k Python : Convert(cast) bytes to string example
+5.7k Javascript : How to replace HTML inside <div>?
+7.6k Golang : Test if an input is an Armstrong number example
+7.8k Golang : Grayscale Image
+26.2k Golang : Convert(cast) string to uint8 type and back to string
+10.5k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+15.5k Golang : Get checkbox or extract multipart form data value example
+4.6k Golang : How to pass data between controllers with JSON Web Token
+10.1k Golang : How to check if a website is served via HTTPS