Search
 
SCRIPT & CODE EXAMPLE
 

CPP

max element in array c++ stl

*max_element (first_index, last_index);
ex:- for an array arr of size n
*max_element(arr, arr + n);
Comment

c++ max of array

cout << " max element is: " << *max_element(array , array + n) << endl;
Comment

find max element in array c++

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

array max and minimum element c++

class findMaxMinFromArray
{
public:
    //! Find the maximum element from an array

    void arrayInput(int arr[], int size)
    {
        arr[size] = {0};
        for (int i = 0; i < size; i++)
        {
            cin >> arr[i];
        }
    }

    int getMaxUsingSort(int arr[], int size)
    {
        arrayInput(arr, size);

        sort(arr, arr + size, greater<int>());

        int max_element = arr[0];
        return max_element;
    }

    void getMaxMin(int num[], int size)
    {
        arrayInput(num, size);

        int max_num = INT32_MIN, min_num = INT32_MAX;

        for (int i = 0; i < size; i++)
        {
            if (num[i] > max_num)
                max_num = num[i];

            if (num[i] < min_num)
                min_num = num[i];
        }
        cout << "Max number of the array: " << max_num << endl;
        cout << "Minimum number of the array: " << min_num << endl;
    }

    void getMaxMinUsingSTL(int num[], int size)
    {
        //* Using STL
        arrayInput(num, size);

        cout << "Maximum element: " << *max_element(num, num + size) << endl;
        cout << "Minimum element: " << *min_element(num, num + size) << endl;
    }
};
Comment

max element of an array stl c++

    vector<int>arr {1, 34 , 50, 4, 400};
    int maximumElement = *max_element(arr.begin(), arr.end());
    int minimumElement = *min_element(arr.begin(), arr.end());
Comment

Max element in an array with the index in c++

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

c++ function of find maximum value in an array

*max_element (first_index, last_index);
Comment

PREVIOUS NEXT
Code Example
Cpp :: vector size for loop 
Cpp :: c++ cast char to string 
Cpp :: c++ reference 
Cpp :: c++ do while loop 
Cpp :: iterate vector in reverse c++ 
Cpp :: hamming distance c++ 
Cpp :: append string cpp 
Cpp :: calloc c++ 
Cpp :: how to get size of 2d vector in c++ 
Cpp :: c++ Sum of all the factors of a number 
Cpp :: pointer address to string 
Cpp :: c++ keyboard input 
Cpp :: for c++ 
Cpp :: concat two vectors c++ 
Cpp :: filling 2d array with 0 c++ 
Cpp :: for loop f# 
Cpp :: change colour of output to terminal c++ 
Cpp :: cpp absolute value 
Cpp :: find kth max and min element in an array 
Cpp :: c++ vs g++ 
Cpp :: how to split string into words c++ 
Cpp :: iterate through list c++ 
Cpp :: Reverse words in a given string solution in c++ 
Cpp :: C++ New Lines 
Cpp :: vector library c++ 
Cpp :: ++ how to write quotation mark in a string 
Cpp :: c for loop decrement 
Cpp :: read string with spaces in c++ 
Cpp :: calculator in cpp 
Cpp :: stack class implementation to file unix-style in c++ 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =