valarray min() in C++ Last Updated : 23 Jun, 2020 Comments Improve Suggest changes Like Article Like Report The min() function is defined in valarray header file. This function returns the smallest value contained in the valarray. Syntax: T min() const; Returns: This function returns the minimum value in the valarray. Below programs illustrate the above function: Example 1:- CPP // C++ program to demonstrate // example of min() function. #include <bits/stdc++.h> using namespace std; int main() { // Initializing valarray valarray<int> varr = { 3, 2, 1, 4, 5 }; // Displaying minimum element of valarray cout << "The smallest element" << " of valarray is = " << varr.min() << endl; return 0; } Output: The smallest element of valarray is = 1 Example 2:- CPP // C++ program to demonstrate // example of min() function. #include <bits/stdc++.h> using namespace std; int main() { // Initializing valarray valarray<int> varr = { 22, 24, 36, 42, 12 }; // Displaying minimum element of valarray cout << "The smallest element " << "of valarray is = " << varr.min() << endl; return 0; } Output: The smallest element of valarray is = 12 Comment More infoAdvertise with us Next Article valarray min() in C++ bansal_rtk_ Follow Improve Article Tags : Misc C++ Programs C++ CPP-Functions cpp-valarray +1 More Practice Tags : CPPMisc Similar Reads Print Minimum of all Subarrays using set in C++ STL Given an array of size N and an integer K, find the minimum for each and every contiguous subarray of size K. Examples: Input : arr[] = {5, 3, 4, 1, 1}, K = 3 Output : 3 1 1 Input : arr[] = {1, 2, 3, 4, 1, 6, 7, 8, 2, 1}, K = 4 Output : 1 1 1 1 1 2 1 Prerequisite: Sliding Window Technique Set in C++ 3 min read C++ Program to Find closest number in array Given an array of sorted integers. We need to find the closest value to the given number. Array may contain duplicate values and negative numbers. Examples: Input : arr[] = {1, 2, 4, 5, 6, 6, 8, 9} Target number = 11 Output : 9 9 is closest to 11 in given array Input :arr[] = {2, 5, 6, 7, 8, 8, 9}; 4 min read How to Find Minimum Element in a Vector in C++? Given a vector of n elements, the task is to find the minimum element using C++.ExamplesInput: v = {2, 4, 1, 5, 3}Output: 1Explanation: 1 is the smallest element in the vectorInput: v = {12, 34, 5, 7}Output: 5Explanation: 5 is the smallest element in the vector.Following are the 6 different methods 4 min read Smallest Pair Sum in an array Given an array of distinct integers arr[], the task is to find a pair which has the minimum sum and print the sum. Examples: Input: arr[] = {1, 2, 3} Output: 3 The pair (1, 2) will have the minimum sum pair i.e. 1 + 2 = 3 Input: arr[] = {3, 5, 6, 2} Output: 5 Approach: Find the minimum element from 5 min read Working with Array and Vectors using STL in C++ Using STL library it is very easy to perform certain basic operations on array like Sorting, searching, sum of elements, finding minimum and maximum element of the array. Sorting Sorting can be done with the help of sort() function. sort(starting_index, last_index) â To sort the given array/vector. 6 min read How to Find the Range of Numbers in an Array in C++? The range of numbers in an array means the difference between the maximum value and the minimum value in the given array. In this article, we will learn how to find the range of numbers in an array in C++. For Example, Input: myArray = {5,10,15,30,25}; Output: Range: 25Range Within an Array in C++To 2 min read How to Find the Range of Values in a 2D Array in C++? In C++, 2D arrays are also known as a matrix, and the range of numbers in a 2D array means the maximum and the minimum value in which the numbers lie in the given 2D array. In this article, we will learn how to find the range of numbers in a 2D array in C++. For Example, Input: my2DArray= {{80, 90, 2 min read C++ Program for Minimum product pair an array of positive Integers Given an array of positive integers. We are required to write a program to print the minimum product of any two numbers of the given array.Examples: Input : 11 8 5 7 5 100 Output : 25 Explanation : The minimum product of any two numbers will be 5 * 5 = 25. Input : 198 76 544 123 154 675 Output : 744 3 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 How to Find the Third Smallest Number in an Array in C++? In C++, an array is the collection of similar data elements that are stored in the contiguous memory location and we can access these elements directly by their index value. In this article, we will learn how to find the third smallest element in an array in C++. If there is no third smallest elemen 2 min read Like