1 2 3 4 5 6 7 8 9 10 11 12 |
//============================================= max
// From algorithms/arrayfuncs.cpp
// Returns the maximum value in an array.
float max(float a[], int size) {
assert(size > 0); // Note 1.
float maxVal = a[0]; // Note 2.
for (int i=1; i<size; i++) {
if (a[i] > maxVal) {
maxVal = a[i];
}
}
return maxVal;
}//end max
|
1 2 3 4 5 6 7 8 9 10 11 12 |
//============================================= maxIndex
// From algorithms/arrayfuncs.cpp
// Returns the index of the maximum value in an array.
int maxIndex(float a[], int size) {
assert(size > 0);
int maxIndex = 0;
for (int i=1; i<size; i++) {
if (a[i] > a[maxIndex]) {
maxIndex = i;
}
}
return maxIndex;
}//end maxIndex
|