溫馨提示×

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

c++
小億
372
2024-06-06 16:48:20
欄目: 編程語言

在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中的最小值。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女