Program in Go language to Find Largest Element of an Array
Simple program using array and for loop to takes n number of element from user (where, n is specified by user) and store all elements data in an array. Then, this program displays the largest element of that array using loops.
Example
// Golang Program to Find Largest Element of an Array
package main
import "fmt"
func main(){
var num[100] float64
var temp int
fmt.Print("Enter number of elements: ")
fmt.Scanln(&temp)
for i := 0; i < temp; i++ {
fmt.Print("Enter the number : ")
fmt.Scan(&num[i])
}
for j := 1; j < temp; j++ {
if( num[0] < num[j] ) {num[0] = num[j]}
}
fmt.Print("The largest number is : ",num[0])
}
Output
Enter number of elements: 5
Enter the number : 5.2
Enter the number : 6
Enter the number : -9.8
Enter the number : 0.3
Enter the number : 5
The largest number is : 6
Most Helpful This Week
Interface embedding and calling interface methods from another package in Go (Golang)
How do you handle HTTP Client server load balancing in Go?
Explain in Brief Golang error handling best practices
State and Props in React
What is the default HTTP server in Go?
Golang program to generate number of slices permutations of number entered by user