0
Programme to print shortest element of a given array
write the logic to print out smallest element of an array without using built in function
2 Answers
0
int[] numbers = {1, 4, 5, 6, 8, 8};
int lowest = numbers[0];
for (int index = 1; index < numbers.length; index ++) {
if (numbers[index] < lowest) {
lowest = numbers [index];
}
}
- 1
take the Min variable as some high value and the check all the elements of the array, for each element check if it is less than the Min variable, if yes then Min=element else skip. you will get the Min element after traversing the whole array.