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
+37.7k Golang : Read a text file and replace certain words
+6.2k Golang : Break string into a slice of characters example
+5.7k Facebook : How to force facebook to scrape latest URL link data?
+10.1k Golang : Wait and sync.WaitGroup example
+4.7k Golang : Calculate a pip value and distance to target profit example
+17.3k Golang : Find smallest number in array
+8.8k Golang : Go as a script or running go with shebang/hashbang style
+4.6k Golang : A program that contain another program and executes it during run-time
+13.2k Android Studio : Password input and reveal password example
+50.5k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+13k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message