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 :: C++ string initialization 
Cpp :: cpp initialize multidimensional vector 
Cpp :: c++ simple projects 
Cpp :: c++ prime sieve 
Cpp :: segmented sieve cpp 
Cpp :: max_element c++ 
Cpp :: create file c++ 
Cpp :: c++ inline in .cpp and not in header 
Cpp :: Parenthesis Checker using stack in c++ 
Cpp :: restting a queue stl 
Cpp :: vector size for loop 
Cpp :: vector reverse function in c++ 
Cpp :: sort 0 1 2 leetcode 
Cpp :: how to use char in c++ 
Cpp :: how to make an overloaded constructor in c++ 
Cpp :: c++ string to char array 
Cpp :: c++ pi float 
Cpp :: c++ array size 
Cpp :: To Lower Case leetcode solution in c++ 
Cpp :: how to find last character of string in c++ 
Cpp :: hello world in c/++ 
Cpp :: c++ progress bar 
Cpp :: c++ get the line which call a function 
Cpp :: binary search c++ 
Cpp :: compute power of number 
Cpp :: struct c++ 
Cpp :: cpp lambda function 
Cpp :: cin exceptions c++ 
Cpp :: vector iterating 
Cpp :: C++ Integer Input/Output 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =