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

17th Aug 2016, 9:46 AM
Abhi Bhardwaj
Abhi Bhardwaj - avatar
2 Réponses
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]; } }
17th Aug 2016, 10:56 AM
WPimpong
WPimpong - avatar
- 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.
17th Aug 2016, 9:57 AM
Shamim Ali
Shamim Ali - avatar