VOOZH about

URL: https://www.geeksforgeeks.org/go-language/golang-program-to-find-largest-element-in-an-array/

⇱ Golang Program to Find Largest Element in an Array - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Golang Program to Find Largest Element in an Array

Last Updated : 12 Jul, 2025
The task is to find the largest element of an array in Golang by taking input values from the user. Example:
Input: Enter the number of elements: 4 Enter the number : 40 Enter the number : 69 Enter the number : 89 Enter the number : -54 Output: The largest number is : 89
In this program, the user needs to enter the total number of elements in which he wants to perform the comparison and the values. The program will compare all the elements and will return the value of the largest element. Output:
Enter number of elements: 5 Enter the number : 20 Enter the number : -219 Enter the number : 219 Enter the number : 54.87 Enter the number : -1000 The largest number is : 219
Explanation: In the above program, we first take input values from the user. We take a variable temp which will store the size of an array. Then, the comparison is being made until we reach the last element. The loop is then terminated and the value of the largest element is returned to the user.
Comment
Article Tags:

Explore