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
Program in Go language to print Pascal's Triangle
GO Program to Check Whether a Number is Even or Odd
Contains, ContainsAny, Count and EqualFold string functions in Go Language
GO Program to Find the Largest Number Among Three Numbers
GO Program to Find Factorial of a Number
Program in Go language to print Floyd's Triangle