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
Golang program for implementation LZW Data Compression and Uncompression
Golang read csv file into struct
Golang program for implementation of Median of Medians
Naming Conventions for Golang Functions
How do you handle HTTP server health checks in Go?
Program to print pyramid using numbers
How do you read headers in an HTTP response in Go?
GO Program to print full Pyramid using *
How to create Slice using new keyword in Golang?
Golang program for implementation of Bubble Sort