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

PREVIOUS NEXT
Code Example
Cpp :: c++ function 
Cpp :: nth node from end of linked list 
Cpp :: max heap in c++ 
Cpp :: how to create a min priority queue of pair of int, int 
Cpp :: remove last index of the string in c++ 
Cpp :: cpp ifstream 
Cpp :: find primes in a range in c++ 
Cpp :: c++ enum 
Cpp :: read comma separated text file in c++ 
Cpp :: c++ get char of string 
Cpp :: convert integer to string c++ 
Cpp :: round double to 2 decimal places c++ 
Cpp :: c++ do while loop 
Cpp :: c++ binary search 
Cpp :: how to use char in c++ 
Cpp :: c++ int 
Cpp :: string to uint64_t c++ 
Cpp :: fast way to check if a number is prime C++ 
Cpp :: string to upper c++ 
Cpp :: swap elements array c++ 
Cpp :: How to write into files in C++ 
Cpp :: cpp when use size_t 
Cpp :: function in struct c++ 
Cpp :: new float array c++ 
Cpp :: C++ float and double Different Precisions For Different Variables 
Cpp :: Converting to string c++ 
Cpp :: dynamic allocation c++ 
Cpp :: c++ lettura file 
Cpp :: ++ how to write quotation mark in a string 
Cpp :: vectors c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =