Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

minimum or maximum in array c++

#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;
 
int main()
{
    int arr[] = { 4, 2, 1, 6, -8, 5 };
 
    int min = INT_MAX, max = INT_MIN;
    for (int i: arr)
    {
        if (i < min) {
            min = i;
        }
 
        if (i > max) {
            max = i;
        }
    }
 
    std::cout << "The min element is " << min << std::endl;
    std::cout << "The max element is " << max << std::endl;
 
    return 0;
}
Source by www.techiedelight.com #
 
PREVIOUS NEXT
Tagged: #minimum #maximum #array
ADD COMMENT
Topic
Name
3+7 =