- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 a Vector using STL in C++?
In this tutorial, we will be discussing a program to understand how to find the maximum element of a vector using STL in C++.
To find the maximum element from a given vector, we will be using the *max_element() method from STL library.
Example
#include <bits/stdc++.h> using namespace std; int main(){ //defining the vector vector<int> a = { 1, 45, 54, 71, 76, 12 }; cout << "Vector: "; for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl; //finding the maximum element cout << "Max Element = " << *max_element(a.begin(), a.end()); return 0; }
Output
Vector: 1 45 54 71 76 12 Max Element = 76
Advertisements