#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;
}
(function () {
const arr = [23, 65, 3, 19, 42, 74, 56, 8, 88];
function findMaxArrValue(arr) {
if (arr.length) {
let max = -Infinity;
for (let num of arr) {
max = num > max ? num : max;
}
return max;
}
return 0; // or any value what you need
}
console.log(findMaxArrValue(arr)); // => 88
})();
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 ( ͡~ ͜ʖ ͡°)
---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 ];
}