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
GO Program to Generate Multiplication Table
GO language program with an example of Hash Table
Program in Go language to Program to Add Two Matrix Using Multi-dimensional Arrays
Program in Go language to Calculate Average Using Arrays
GO Program to Calculate Area of Rectangle and Square
GO Program to take user input and addition of two strings