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

Answer:

Two if-structures should do the trick


Structured Max Three

Max of Three Flowchart

The flowchart shows this function. The code for this flowchart is


/*
pre-condition: 
  a, b, and c are integers.
exit condition: 
  return the maximum of the three arguments.
*/
int maxThree(int a, int b, int c)
{
  int max;
  if (a >= b && a >= c)
    max = a;
  else
    if (b >= c)
      max = b;
    else
      max = c;

  return max;
}

The flowchart is easy to follow, and the code follows it, so this is a good design, at least according to structuring principles.


QUESTION 2:

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