C++ Standard Library C++ STL Library

C++ <valarray> - min() Function



The C++ valarray::min function returns the minimum value of the elements of a valarray. It uses operator< to compare the elements. If the size of the valarray is zero, the behavior is undefined.

Syntax

T min() const;

Parameters

No parameter is required.

Return Value

Returns the minimum value of elements of valarray.

Time Complexity

Depends on library implementation.

Example:

In the example below, the valarray::min function is used to find out the minimum value of the elements of given valarray.

#include <iostream>
#include <valarray>
using namespace std;
 
int main (){
  valarray<int> varr = {10, 20, 25, 5, 15};

  //finding the minimum value of 
  //elements of the valarray
  cout<<"The minimum value is: "
      <<varr.min();  

  return 0;
}

The output of the above code will be:

The minimum value is: 5

❮ C++ <valarray> Library