C Program to Find Minimum Value in Array Last Updated : 20 Nov, 2024 Comments Improve Suggest changes Like Article Like Report In this article, we will learn how to find the minimum value in the array.The easiest and straightforward method is to iterate through each element of the array, comparing each value to an assumed minimum and updating it if the current value is less. C #include <stdio.h> int findMin(int arr[], int n) { // Assume first element as minimum int min = arr[0]; for (int i = 1; i < n; i++) { // Update m if arr[i] is smaller if (arr[i] < min) { min = arr[i]; } } return min; } int main() { int arr[] = {5, 2, 7, 6}; int n = sizeof(arr) / sizeof(arr[0]); // Find and print minimum value in arr printf("%d\n", findMin(arr, n)); return 0; } Output2 This method is simply the linear search algorithm modified to find the minimum element.There are also some other ways to find the minimum value in array in C. They are as follows:Table of ContentSorting MethodRecursive MethodRecursive MethodThe function reduces the search size by comparing the last element with the minimum of the remaining elements and recursively processing the rest of the array. This continues until the base case is reached, where a single element remains, which is returned as the minimum. C #include <stdio.h> // Recursive approach to find the minimum element int findMin(int arr[], int n) { // Base case: Only one element if (n == 1) return arr[0]; // Find minimum from the rest of the array int min = findMin(arr, n - 1); // Return smaller element between curent element // or minimum element in rest of the array return arr[n - 1] < min ? arr[n - 1] : min; } int main() { int arr[] = {5, 2, 7, 6}; int n = sizeof(arr) / sizeof(arr[0]); // Finding and printing the minimum element printf("%d\n", findMin(arr, n)); return 0; } Output2 While this approach is intuitive, it can be less efficient than iterative method for large arrays due to the space required for recursive calls.By SortingIn an array sorted in ascending order, the minimum element is present at the beginning (0th index). The array can be sorted using qsort() function with a custom comparator for ascending order. C #include <stdio.h> #include <stdlib.h> // Comparator function for qsort (ascending order) int compare(const void *a, const void *b) { return (*(int *)a - *(int *)b); } int findMin(int arr[], int n) { // Sort the array using qsort qsort(arr, n, sizeof(int), compare); // The first element is smallest after sorting return arr[0]; } int main() { int arr[] = {5, 2, 7, 6}; int n = sizeof(arr) / sizeof(arr[0]); // Find and print the minimum element in arr printf("%d\n", findMin(arr, n)); return 0; } Output2 This method is less efficient than linear search for just finding the minimum element but more suitable for finding the n-th smallest element. Comment More infoAdvertise with us Next Article C Program to Find Minimum Value in Array kumarsinghritik22 Follow Improve Article Tags : C Programs C Language C-Arrays C Array Programs C Examples +1 More Similar Reads How to Find Maximum Value in an Array in C? In C, arrays are data structures that allow the user to store a collection of data of the same type. In this article, we will learn how we can find the maximum value in an array in C. Example Input: arr = {5,3,1,2,4} Output: The maximum value of the array is: 5Finding Maximum Value in an Array in CW 2 min read C Program to Find the Maximum and Minimum Element in the Array In this article, we will discuss different ways to find the maximum and minimum elements of the array in C.The simplest method to find the maximum and minimum element of the array is iterates through the array and compare each element with the assumed minimum and maximum and update them if the curre 3 min read C Program For Maximum and Minimum of an Array Given an array of size N. The task is to find the maximum and the minimum element of the array using the minimum number of comparisons. Examples: Input: arr[] = {3, 5, 4, 1, 9}Output: Minimum element is: 1Â Â Â Â Â Â Â Maximum element is: 9 Input: arr[] = {22, 14, 8, 17, 35, 3}Output:Â Minimum eleme 7 min read How to Find the Range of Numbers in an Array in C? The range of numbers within an array is defined as the difference between the maximum and the minimum element present in the array. In this article, we will learn how we can find the range of numbers in an array in C. Example Input:int arr[] = { 23, 12, 45, 20, 90, 89, 95, 32, 65, 19 }Output: The ra 2 min read How to Find the Mode of Numbers in a Sorted Array in C? The mode of the given numbers can be defined as the value that occurs the most in the given dataset or the value with the highest frequency. In this article, we will learn how to find the mode of all elements in a sorted array of integers in C. Example: Input:myArray = {1, 2, 3, 3, 5, 5, 5, 5, 6, 7} 2 min read C Program to Implement Min Heap In this article, we will learn the implementation of min heap in C programming language. A heap is a data structure like a tree with some special properties. The basic requirement of the heap is that the value of a node must be greater than equal to (or smaller than equal to) the value of its childr 10 min read C Program to Find minimum sum of factors of number Write a C program for a given number N, the task is to find the minimum sum of its factors. Examples: Input : 12Output : 7Explanation: Following are different ways to factorize 12 andsum of factors in different ways.12 = 12 * 1 = 12 + 1 = 1312 = 2 * 6 = 2 + 6 = 812 = 3 * 4 = 3 + 4 = 712 = 2 * 2 * 3 2 min read How to Find the Smallest Number in an Array in C++? In C++, arrays are the data types that store the collection of the elements of other data types such as int, float, etc. In this article, we will learn how to find the smallest number in an array using C++. For Example,Input: myVector = {10, 3, 10, 7, 1, 5, 4} Output: Smallest Number = 1Find the Sma 2 min read Java Program to Print the Smallest Element in an Array Java provides a data structure, the array, which stores the collection of data of the same type. It is a fixed-size sequential collection of elements of the same type. Example: arr1[] = {2 , -1 , 9 , 10} output : -1 arr2[] = {0, -10, -13, 5} output : -13 We need to find and print the smallest value 3 min read How to Find the Minimum Element in a List in C++? In C++, a list is a sequence container provided by the STL library that stores data in non-contiguous memory locations efficiently. In this article, we will learn how to find the minimum element in a list in C++. Example: Input: myList = {30, 10, 20, 50, 40};Output: The minimum element in the list i 2 min read Like