- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the maximum element of an Array using STL in C++?
Here we will see how to find the maximum element. So if the array is like [12, 45, 74, 32, 66, 96, 21, 32, 27], then max element is 96. We can use the max_element() function present in algorithm.h header file to get the maximum element.
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); }
Output
Array is like: 12 45 74 32 66 96 21 32 27 Max Element is: 96
- Related Articles
- How to find the minimum and maximum element of an Array using STL in C++?
- How to find the maximum element of a Vector using STL in C++?
- 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++?
- Program to find the minimum (or maximum) element of an array in C++
- How to reverse an Array using STL in C++?
- How to sort an Array using STL in C++?
- C# program to find maximum and minimum element in an array
- PHP program to find the maximum element in an array
- Shuffle an Array using STL in C++
- Find the only different element in an array using C++
- All reverse permutations of an array using STL 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?
- Find elements of an array which are divisible by N using STL in C++

Advertisements