
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
How to find the minimum and maximum element of an Array using STL in C++?
Here we will see how to find the maximum and minimum element from an array. So if the array is like [12, 45, 74, 32, 66, 96, 21, 32, 27], then max element is 96, and min element is 12. We can use the max_element() function and min_element() function, present in algorithm.h header file to get the maximum and minimum elements respectively.
Example
#include<iostream> #include<algorithm> using namespace std; int main() { int arr[] = {12, 45, 74, 32, 66, 96, 21, 32, 27}; int n = sizeof(arr) / sizeof(arr[0]); cout << "Array is like: "; for (int i = 0; i < n; i++) cout << arr[i] << " "; cout << "\nMax Element is: " << *max_element(arr, arr + n); cout << "\nMin Element is: " << *min_element(arr, arr + n); }
Output
Array is like: 12 45 74 32 66 96 21 32 27 Max Element is: 96 Min Element is: 12
- Related Articles
- How to find the maximum element of an Array using STL in C++?
- C# program to find maximum and minimum element in an array\n
- Program to find the minimum (or maximum) element of an array in C++
- How to find the maximum element of a Vector using STL in C++?
- Maximum and minimum of an array using minimum number of comparisons in C
- How to find minimum element in an array using linear search in C language?
- How to find minimum element in an array using binary search in C language?
- C++ Program to Find Minimum Element in an Array using Linear Search
- C++ Program to Find the Minimum element of an Array using Binary Search approach
- C++ Program to Find Maximum Element in an Array using Binary Search
- How to find the sum of elements of an Array using STL in C++?
- Rearrange an Array in Maximum Minimum Form using C++
- How to reverse an Array using STL in C++?
- How to sort an Array using STL in C++?
- Recursive Programs to find Minimum and Maximum elements of array in C++

Advertisements