max in arr cpp code example
Example 1: c++ max of array
cout << " max element is: " << *max_element(array , array + n) << endl;
Example 2: maximum number from Array
---without sort method---
public static int maxValue( int[] n ) {
int max = Integer.MIN_VALUE;
for(int each: n)
if(each > max)
max = each;
return max;
---with sort method---
public static int maxValue( int[] n ) {
Arrays.sort( n );
return n [ n.lenth-1 ];
}