- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a Golang program to find the element with the minimum value in an array
Examples
- A1 = [2, 4, 6, 7, 8, 10, 3, 6, 0, 1]; Minimum number is 0;
- A2 = [12, 14, 16, 17, 18, 110, 13, 16, 10, 11]; Minimum number is 10;
Approach to solve this problem
Step 1: Consider the number at the 0th index as the minimum number, min_num = A[0].
Step 2: Compare min_num with every number in the given array, while iterating.
Step 3: If a number is smaller than min_num, then assign that number to min_num.
Step 4: At the end of iteration, return min_num;
Program
package main import "fmt" func findMinElement(arr []int) int { min_num := arr[0] for i:=0; i<len(arr); i++{ if arr[i] < min_num { min_num = arr[i] } } return min_num } func main(){ arr := []int{2, 3, 5, 7, 11, 13} fmt.Println(findMinElement(arr)) fmt.Println(findMinElement([]int{2, 4, 6, 7, 8, 10, 3, 6, 0, 1})) fmt.Println(findMinElement([]int{12, 14, 16, 17, 18, 110, 13, 16, 10, 11})) }
Output
2 0 10
- Related Articles
- Write a Golang program to find the frequency of an element in an array
- Write a Golang program to find the frequency of each element in an array
- Write a Golang program to search an element in an array
- Write a program in Go language to find the element with the maximum value in an array
- Write a Golang program to search an element in a sorted array
- PHP program to find the minimum element in an array
- Write a Golang program to find pairs with the given sum in an array(O(n2))
- Write a Golang program to find pairs with the given sum in an array(O(n))
- Write a Java program to find the first array element whose value is repeated an integer array?
- Write a Golang program to find pairs with given sum in an array(O(nlogn))
- Write a Golang program to reverse an array
- Program to find the minimum (or maximum) element of an array in C++
- C# program to find maximum and minimum element in an array
- Write a program to find the index of particular element in an array in javascript?
- C++ Program to Find Minimum Element in an Array using Linear Search

Advertisements