📜  valarray min()在C ++中

📅  最后修改于: 2021-05-31 23:13:15             🧑  作者: Mango

min()函数在valarray头文件中定义。此函数返回valarray中包含的最小值。

句法:

T min() const;

返回:该函数返回的valarray的最小值

下面的程序说明了上述函数:

范例1:-

// C++ program to demonstrate
// example of min() function.
  
#include 
using namespace std;
  
int main()
{
    // Initializing valarray
    valarray varr = { 3, 2, 1, 4, 5 };
  
    // Displaying minimum element of valarray
    cout << "The smallest element"
         << " of valarray is = "
         << varr.min() << endl;
  
    return 0;
}
输出:
The smallest element of valarray is = 1

示例2:

// C++ program to demonstrate
// example of min() function.
  
#include 
using namespace std;
  
int main()
{
    // Initializing valarray
    valarray varr = { 22, 24, 36, 42, 12 };
  
    // Displaying minimum element of valarray
    cout << "The smallest element "
         << "of valarray is = "
         << varr.min() << endl;
  
    return 0;
}
输出:
The smallest element of valarray is = 12
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”