give max elemnent of array code example
Example 1: get max element of array javascript
const maxMinArray = (a,b,...c) =>{
let array = [a,b];
let newArray = array.concat(c);
let max = 0;
for(let number of newArray){
if(max<number){
max = number;
}
}
let min = max;
for(let number of newArray){
if(number<min){
min = number;
}
}
return console.log(max + ' ' + min)
}
maxMinArray(12,14,15,23)
Example 2: max element in array
int max;
max=INT_MIN;
for(int i=0;i<ar.length();i++){
if(ar[i]>max){
max=ar[i];
}