I agree with BSCode. As this sounds like a class assignment type question, it is probably being covered in an intro-level course, and they may not have even gotten to arrays yet!
Using if...statements is probably your best bet. I would use two 'checks' in each statement - for example, I would want to check if a is bigger than b AND if a is bigger than c.
Don't do that because you'll be throwing away valuable information then. Write it
out and you'll see that you're basically doing this:
-
if (a >= b && a >= c) max= a;
-
else if (b >= a && b >= c) max = b;
-
else if (c >= a && c >= b) max= c;
... and then you have to do the same for the minimum value; on top of that
you'll be testing quite a bit of comparisons twice.
Better do this then:
-
if (a >= b)
-
if (a >= c) { max= a; if (b >= c) min= c; else min= b; }
-
else { max= c; min= b; }
-
else if (b >= c)
-
{ max= b; if (a >= c) min= c; else min= a; }
-
else { max= c; if (a >= b) min= b; else min= a; }
kind regards,
Jos (<--- cycle squeezer ;-)