इस ट्यूटोरियल में, हम C++ में STL का उपयोग करके वेक्टर का अधिकतम तत्व खोजने के तरीके को समझने के लिए एक प्रोग्राम पर चर्चा करेंगे।
दिए गए वेक्टर से अधिकतम तत्व खोजने के लिए, हम STL लाइब्रेरी से *max_element() विधि का उपयोग करेंगे।
उदाहरण
#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; }आउटपुट
Vector: 1 45 54 71 76 12 Max Element = 76