Answers for "find maximum value in array"

2

Find the maximum number of an array js

var arr = [1, 2, 3];
var max = arr.reduce(function(a, b) {
  return Math.max(a, b);
});
Posted by: Guest on October-22-2020
6

find maximum number in array

#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;
}
Posted by: Guest on April-28-2020
1

get max number in array

console.log(arrayNumbers.sort((a, b) => a - b ));
Posted by: Guest on November-06-2021
1

Find Maximum array

Array -- Find Maximum
Write a method that can find the maximum number from an int Array
Solution 1:
public static void main(String[] args) {
    int[] arr = new int[]{2,4,6,8,20};
    System.out.println(maxValue(arr));

public static int maxValue( int[]  n ) {
int max = Integer.MIN_VALUE;
for(int each: n)
if(each > max)
max = each;
 
return max;
}
 
Solution 2:
public static int maxValue( int[]  n ) {
Arrays.sort( n );
return  n [ n.lenth-1 ];
}
Posted by: Guest on September-29-2021
3

how to find max in array

int[] a = new int[] { 20, 30, 50, 4, 71, 100};
		int max = a[0];
		for(int i = 1; i < a.length;i++)
		{
			if(a[i] > max)
			{
				max = a[i];
			}
		}
		
		System.out.println("The Given Array Element is:");
		for(int i = 0; i < a.length;i++)
		{
			System.out.println(a[i]);
		}
		
		System.out.println("From The Array Element Largest Number is:" + max);
Posted by: Guest on May-03-2020
0

Find the maximum number of an array js

Math.max(10, 20);   //  20
Math.max(-10, -20); // -10
Math.max(-10, 20);  //  20
Posted by: Guest on October-22-2020

Code answers related to "find maximum value in array"

Browse Popular Code Answers by Language