找10個整數中的最大值的c++代碼

以下是使用C++編寫的找10個整數中的最大值的代碼:

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

int main() {
    std::vector<int> nums = {5, 8, 2, 7, 3, 9, 1, 4, 6, 0}; // 這裡填寫需要找最大值的10個整數

    int max_num = *std::max_element(nums.begin(), nums.end());

    std::cout << "最大值為:" << max_num << std::endl;

    return 0;
}

這段代碼使用了STL中的std::max_element函式來找出向量中的最大值。首先,我們定義了一個包含10個整數的向量nums,然後使用std::max_element函式找到向量中的最大值,並將其存儲在變數max_num中。最後,我們使用std::cout將最大值輸出到控制台。