*max_element (first_index, last_index);
ex:- for an array arr of size n
*max_element(arr, arr + n);
cout << " max element is: " << *max_element(array , array + n) << endl;
#include <iostream>
using namespace std;
//How to find max element in C++
int main() {
int n;
cout <<"How many element yo will enter?"<<endl;
cin >> n;
int arr[n];
for(int i=0;i<n;i++){
cout << "Your "<< i+1 <<" number : ";
cin >> arr[i];
}
for(int i=0;i<n;i++){
if(arr[0]<arr[i]){
arr[0]=arr[i];
}
}
cout << "The max element is :"<<arr[0];
return 0;
}
vector<int>arr {1, 34 , 50, 4, 400};
int maximumElement = *max_element(arr.begin(), arr.end());
int minimumElement = *min_element(arr.begin(), arr.end());
int main(int argc, char** argv) {
int A[4] = {0, 2, 3, 1};
const int N = sizeof(A) / sizeof(int);
cout << "Index of max element: "
<< distance(A, max_element(A, A + N))
<< endl;
return 0;
}
Code Example |
---|
Cpp :: dynamic allocation c++ |
Cpp :: c++ compile to exe command line |
Cpp :: C++ New Lines |
Cpp :: mac emoji shortcut |
Cpp :: how to cout in c++ |
Cpp :: demonstrate constructor |
Cpp :: c++ clip values |
Cpp :: c++ find object in vector by attribute |
Cpp :: c++ finding gcd |
Cpp :: c++ exceptions |
Cpp :: create matrix cpp |
Cpp :: check even or odd c++ |
Cpp :: map in cpp |
Cpp :: how to replace part of string with new string c++ |
Cpp :: unpack tuple c++ |
Cpp :: kmp algorithm c++ |
Cpp :: double array c++ |
Cpp :: C++ Pi 4 Decimal |
Cpp :: c++ fill two dimensional array |
Cpp :: c++ string_t to string |
Cpp :: c++ variable type |
Cpp :: set size of a vector c++ |
Cpp :: potato |
Cpp :: c++ call by value |
Cpp :: find an element in vector of pair c++ |
Cpp :: How to pass a multidimensional array to a function in C and C++ |
Cpp :: compare function in c++ |
Cpp :: if not c++ |
Cpp :: converting int to string c++ |
Cpp :: c++ structs |