how to find maximum value in c++ code example

Example 1: c++ max of array

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

Example 2: c++ how to get maximum value

x = 1, y  = 2;
fmax(x , y);
//if you want to print it right away:
cout << fmax(x , y);
//if you want to store it:
int j = fmax(x, y);
cout << j;

//output 2

Example 3: how to find maximum value in c++

int maximumValue(int array[] , int n){
  int max=array[0];
  for int i=1;i < n;i++ {
    if (array[i] > max)
      max = array[i];
    
  }
  return max;
}

Tags:

Misc Example