Answers for "finding the minimum and index from a vector c++"

C++
0

c++ find minimum value in vector

#include <iostream>
#include <algorithm> 
#include <vector> 
using namespace std;

int main()
{
    vector<int> a = {1,5,6,7,8,3};
    cout << *min_element(a.begin(), a.end());
    return 0;
}
Posted by: Guest on February-09-2022
0

get min and max element index from vector c++

int maxElementIndex = std::max_element(v.begin(),v.end()) - v.begin();
int maxElement = *std::max_element(v.begin(), v.end());

int minElementIndex = std::min_element(v.begin(),v.end()) - v.begin();
int minElement = *std::min_element(v.begin(), v.end());
Posted by: Guest on September-15-2020

Code answers related to "finding the minimum and index from a vector c++"

Browse Popular Code Answers by Language