扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

c++输出最小值的方法是什么

扬州沐宇科技
2024-06-06 16:48:20
c++

在C++中,可以使用STL中的min_element函数来输出最小值。这个函数需要在#include <algorithm>头文件中使用。下面是一个示例代码:

#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    std::vector<int> numbers = {4, 2, 7, 1, 9, 5};
    
    auto min_value = *std::min_element(numbers.begin(), numbers.end());
    
    std::cout << "The minimum value is: " << min_value << std::endl;

    return 0;
}

运行上面的代码,将会输出数组numbers中的最小值。

扫码添加客服微信