go to previous page   go to home page   go to next page


Two if-structures should do the trick

Structured Max Three

Max of Three Flowchart

The flowchart shows this function. The code for this is

pre-condition: a, b, and c are integers.
exit condition: return the maximum of a, b, and c

int maxThree(int a, int b, int c)
  int max;
  if (a >= b && a >= c)
    max = a;
    if (b >= c)
      max = b;
      max = c;

  return max;

The flowchart is easy to follow, and the code matches it, so this is a good structured design.


If the maximum is a, how soon in the code is this known?