Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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;
}
Comment

minimum and maximum value of a vector in C++

#include <iostream>
#include <vector>
#include <algorithm>
 
int main()
{
    std::vector<int> v = {2, 1, 3, 6, 7, 9, 8};
 
    int max = *max_element(v.begin(), v.end());
    int min = *min_element(v.begin(), v.end());
 
    std::cout << min << ", " << max << std::endl;        // 1, 9
 
    return 0;
}
Comment

max and min function vector in c++

// C++ program to find the min and max element
// of Vector using *min_element() in STL
 
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  // Get the vector
  vector<int> a = { 1, 45, 54, 71, 76, 12 };
 
  // Print the vector
  cout << "Vector: ";
  for (int i = 0; i < a.size(); i++)
    cout << a[i] << " ";
  cout << endl;
 
  // Find the min element
  cout << "
Min Element = "
    << *min_element(a.begin(), a.end());
 
  // Find the max element
  cout << "
Max Element = "
    << *max_element(a.begin(), a.end());
  return 0;
}
Comment

c++ max and min of vector

#include <iostream>
#include <algorithm>

template <typename T, size_t N> const T* mybegin(const T (&a)[N]) { return a; }    
template <typename T, size_t N> const T* myend  (const T (&a)[N]) { return a+N; }

int main()
{
    const int cloud[] = { 1,2,3,4,-7,999,5,6 };

    std::cout << *std::max_element(mybegin(cloud), myend(cloud)) << '
';
    std::cout << *std::min_element(mybegin(cloud), myend(cloud)) << '
';
}
Comment

c++ max and min of vector

template <typename T, size_t N> const T* mybegin(const T (&a)[N]) { return a; }    
template <typename T, size_t N> const T* myend  (const T (&a)[N]) { return a+N; }
Comment

c++ max and min of vector

auto it = max_element(std::begin(cloud), std::end(cloud)); // c++11
Comment

PREVIOUS NEXT
Code Example
Cpp :: convert decimal to binary c++ 
Cpp :: default access modifier in c++ in struct 
Cpp :: fork was not declared in this scope 
Cpp :: insertion sort c++ 
Cpp :: c++ read integers from file 
Cpp :: c++ file exists 
Cpp :: structure and function c++ 
Cpp :: cpp split string by space 
Cpp :: c++ map iterator 
Cpp :: what is the difference between i++ and ++ i ? 
Cpp :: sum of vector elements c++ 
Cpp :: c++ map loop through key value 
Cpp :: count occurrences of character in string c++ 
Cpp :: c++ extend class 
Cpp :: string to number in c++ 
Cpp :: c++ switch case break 
Cpp :: sort using lambda c++ 
Cpp :: string length c++ 
Cpp :: define unicode c++ 
Cpp :: int to string c++ 
Cpp :: doubly linked list c++ code 
Cpp :: c++ sieve of eratosthenes 
Cpp :: initialize 2d vector 
Cpp :: c++ program transpose of matrix 
Cpp :: c++ clear char array 
Cpp :: continue c++ 
Cpp :: console colors in C++ 
Cpp :: c++ hello world 
Cpp :: what is thread in c++ 
Cpp :: prisma client 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =