function findHighestNumber(nums) {
let inputs = nums.filter((val, i) => nums.indexOf(val) === i)
let max = Math.max(...nums);
let min = Math.min(...nums);
return max + (-min);
}
console.log(difference([1, 7, 18, -1, -2, 9]));
//For Values
var arr =[1,10,3]
var min = Math.min.apply(null, arr),
max = Math.max.apply(null, arr);
//For Objects
var arr = [{a: 1},{a: 10},{a: 3}]
var values = arr.map(val => val.a);
var max = Math.max.apply(null, values);
console.log(max)
#include <stdio.h>
int main() {
int n;
double arr[100];
printf("Enter the number of elements (1 to 100): ");
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
printf("Enter number%d: ", i + 1);
scanf("%lf", &arr[i]);
}
// storing the largest number to arr[0]
for (int i = 1; i < n; ++i) {
if (arr[0] < arr[i]) {
arr[0] = arr[i];
}
}
printf("Largest element = %.2lf", arr[0]);
return 0;
}
Find largest number from array by function in javascript
function largestElements(numbers) {
var largest = 0;
for (let i = 0; i < numbers.length; i++) {
var elements = numbers[i];
if (elements > largest) {
largest = elements;
}
}
return largest;
}
const numbers = [2, 3, 4, 8, 5, 2, 4];
console.log(largestElements(numbers));
//Output: 8
#include <stdio.h>
int main() {
int n;
double arr[100];
printf("Enter the number of elements (1 to 100): ");
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
printf("Enter number%d: ", i + 1);
scanf("%lf", &arr[i]);
}
// storing the largest number to arr[0]
for (int i = 1; i < n; ++i) {
if (arr[0] < arr[i]) {
arr[0] = arr[i];
}
}
printf("Largest element = %.2lf", arr[0]);
return 0;
}