The negative case is handled easily enough by priming max to the first value in the array rather than assuming zero:
Code:
int compare(int a, int b, int c) {
int tmp[3] = {a, b, c};
int max = tmp[0];
for (int i = 1; i < 3; i++) {
if (tmp[i] > max) {
max = tmp[i];
}
}
return max;
}
It starts by assuming the first element in the array is the maximum, then going from there. Note how the iterator now starts from array index 1 now, as the 0'th has been catered for already by that stage.
If it's a simple test, then you can either use if...else or a single-line ternary operator to do it:
Code:
return a > b ? (a > c ? a : c) : (b > c ? b : c);
but that's not so readable as if...else