Example, for array of ints:
int minValue(int array[]) {
int min=Integer.MAX_VALUE;
for (int i=0; i
if (array[i] < min) min = array[i];
return min;
}
This one won't blow up if passed in a zero-length array
2007-07-24 15:53:16
·
answer #1
·
answered by McFate 7
·
0⤊
0⤋
Declare a variable to hold the lowest number. Set it to the first number in the array. Then, iterate through the array with a loop. In each iteration check to see if the current number is lower than the one in the variable. If it is, set the variable to it. When the loop is done, the variable will hold the lowest number.
2007-07-24 22:08:56
·
answer #2
·
answered by hac 3
·
0⤊
0⤋
First sort the array like this
Arrays.Sort(myArray);
Then, return the first index b/c it will contain the lowest number.
myArray(0) // the lowest number
Aren't I awesome?
BTW, you can create your own comparer to define how the sorting should work or just sort it based on the default type's comparer.
If you are using ints or floats it will work automatically.
2007-07-24 22:51:04
·
answer #3
·
answered by El Gordo 3
·
0⤊
0⤋
that easy too:
float answer = array[0];
try for (int x = 0; ; x++) if (array[x] < answer) answer = array[x];
catch (Exception e) ;
2007-07-24 21:57:41
·
answer #4
·
answered by Andy T 7
·
0⤊
1⤋
try this link
http://www.dreamincode.net/forums/showtopic19413.htm
PongSmart
*don't forget to vote me the best answer, o.k.
2007-07-24 21:35:09
·
answer #5
·
answered by PongSmart 3
·
0⤊
3⤋