1int maxElementIndex = std::max_element(v.begin(),v.end()) - v.begin();
2int maxElement = *std::max_element(v.begin(), v.end());
3
4int minElementIndex = std::min_element(v.begin(),v.end()) - v.begin();
5int minElement = *std::min_element(v.begin(), v.end());
1int main()
2{
3 // Get the vector
4 vector<int> a = { 1, 45, 54, 71, 76, 12 };
5
6 // Print the vector
7 cout << "Vector: ";
8 for (int i = 0; i < a.size(); i++)
9 cout << a[i] << " ";
10 cout << endl;
11
12 // Find the max element
13 cout << "\nMax Element = "
14 << *max_element(a.begin(), a.end());
15 return 0;
16}
1int main(int argc, char** argv) {
2 int A[4] = {0, 2, 3, 1};
3 const int N = sizeof(A) / sizeof(int);
4
5 cout << "Index of max element: "
6 << distance(A, max_element(A, A + N))
7 << endl;
8
9 return 0;
10}
11