2.2k views
2 votes
Assume that max2 is a function that expects two int parameters and returns the value of the larger one. Also assume that four variables, population1, population2, population3, and population4 have already been defined and associated with int values. Write an expression (not a statement!) whose value is the largest of population1, population2, population3, and population4 by calling max2.

1 Answer

4 votes

Final answer:

The largest value of population1, population2, population3, and population4 is found by nesting calls to the max2 function: max2(max2(population1, population2), max2(population3, population4)). This returns the largest value among the four after two comparisons.

Step-by-step explanation:

To write an expression that returns the largest of the values associated with population1, population2, population3, and population4 by using the max2 function, you would need to nest calls to max2 within each other. First, you find the larger of population1 and population2, then the larger of population3 and population4, and finally, you find the larger of the two results. The expression would be:

max2(max2(population1, population2), max2(population3, population4))

This will return the largest value among the four populations by first comparing population1 with population2, and population3 with population4, and then comparing the winners of those two pairs to find the ultimate largest population.

User Rapfaria
by
8.1k points