javascript minimum number in array
const min = arr => Math.min(...arr);
javascript minimum number in array
const min = arr => Math.min(...arr);
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;
}
javascript get minimum value in array
// Getting min value
var arr = [5,1,9,5,7];
var min = Math.min(...arr);
console.log(min); // 1
// Getting max value
var arr = [5,1,9,5,7];
var min = Math.max(...arr);
console.log(min); // 9
Minimum and maximum element in an Array
def divideAndConquer_Max(arr, ind, len):
maximum = -1;
if (ind >= len - 2):
if (arr[ind] > arr[ind + 1]):
return arr[ind];
else:
return arr[ind + 1];
maximum = divideAndConquer_Max(arr, ind + 1, len);
if (arr[ind] > maximum):
return arr[ind];
else:
return maximum;
def divideAndConquer_Min(arr, ind, len):
minimum = 0;
if (ind >= len - 2):
if (arr[ind] < arr[ind + 1]):
return arr[ind];
else:
return arr[ind + 1];
minimum = divideAndConquer_Min(arr, ind + 1, len);
if (arr[ind] < minimum):
return arr[ind];
else:
return minimum;
if __name__ == '__main__':
minimum, maximum = 0, -1;
# array initialization
arr = [6, 4, 8, 90, 12, 56, 7, 1, 63];
maximum = divideAndConquer_Max(arr, 0, 9);
minimum = divideAndConquer_Min(arr, 0, 9);
print("The minimum number in the array is: ", minimum);
print("The maximum number in the array is: ", maximum);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us