Hello
I have this task below & I need someone to tell me if I have done it correctly. The part where I am not sure is if I am correctly checking if the array is empty.
Write a function to find the maximum value in an array of ints a.
int findMax(int a[], int n)
// precondition : a[0..n-1] is an array of ints
// postcondition : returns the maximum value in array or
// INT_MIN if array is emptyRecall that INT_MIN is a predefined constant indicating the minimum value of an integer.
int findMax(int a[], int n) {
/// Homework 2 ///
int max = 0;
if (n >= 0) { // does this check if the array is empty??
for (int i=0; i<n; i++) {
if (a[i] > max) { max = a[i]; }
}
return max;
}
else
return INT_MIN; // array is empty so return INT_MIN
}