How to find the largest and smallest number in an unsorted integer array in C++

1 Answer

0 votes
#include <iostream>
#include <algorithm>

int main() {
    int arr[] = {4, 7, 3, 12, 9, 6, 11, 10};
    
    auto minmax = std::minmax_element(std::begin(arr), std::end(arr));

    std::cout << "min element " << *(minmax.first) << "\n";
    std::cout << "max element " << *(minmax.second) << "\n";
}

    
    
/*
run:
    
min element 3
max element 12
     
*/

 



answered Dec 23, 2024 by avibootz
...