xxxxxxxxxx
var arr = [1, 2, 3];
var max = Math.max(arr);
xxxxxxxxxx
var arr = [1, 2, 3];
var max = arr.reduce(function(a, b) {
return Math.max(a, b);
});
xxxxxxxxxx
#include <stdio.h>
int main() {
int i, n;
float arr[100];
printf("Enter the number of elements (1 to 100): ");
scanf("%d", &n);
for (i = 0; i < n; ++i) {
printf("Enter number%d: ", i + 1);
scanf("%f", &arr[i]);
}
// storing the largest number to arr[0]
for (i = 1; i < n; ++i) {
if (arr[0] < arr[i])
arr[0] = arr[i];
}
printf("Largest element = %.2f", arr[0]);
return 0;
}
xxxxxxxxxx
function getMaxOfArray(numArray) {
return Math.max.apply(null, numArray);
}
xxxxxxxxxx
console.log(Math.max(1, 3, 2));
// expected output: 3
console.log(Math.max(-1, -3, -2));
// expected output: -1
const array1 = [1, 3, 2];
console.log(Math.max(array1));
// expected output: 3
xxxxxxxxxx
function findMaxArrValue(numbers) {
let max = 0;
numbers.forEach((number) => {if (number > max) {max = number}});
return max;
}
console.log(findMaxArrValue([23, 69, 55, 31, 75, 100, 82]));
//Output 100
xxxxxxxxxx
//We define a function findMax that takes an array arr as an argument.
//Inside the function, we use the spread operator (...) to spread the elements of the array as arguments to the Math.max function.
//This effectively finds the maximum element in the array.
const findMax = arr => Math.max(arr);
// Example usage:
const numbers = [10, 5, 8, 20, 3];
const maxNumber = findMax(numbers);
console.log(maxNumber); // Output: 20
xxxxxxxxxx
const findMax = (arr)=>{
let max = 0 ;
for (let index = 0; index < arr.length; index++) {
if (max < arr[index] && max != arr[index]) {
max = arr[index];
}
}
return max;
}
//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)