Problemas
A certain game keeps track of the maximum and minimum scores obtained so far. If num represents the most recent score obtained , which of the following algorithms correctly updates the values of the maximum and the minimum? A If num is greater than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num. B If num is less than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum set the maximum equal to num. C If num is less than the minimum, set the minimum equal to num.Otherwise, if num is less than the maximum set the maximum equal to num. D If num is greater than the minimum, set the minimum equal to num.Otherwise, if num is less than the maximum, set the maximum equal to num.
Solución
Albertomaestro · Tutor durante 5 años
Verificación de expertos
3.7 (251 votos)
Responder
The correct answer is B.<br /><br />Explanation:<br />The question is asking for the algorithm that correctly updates the maximum and minimum values based on the most recent score obtained in a game.<br /><br />Let's analyze each option:<br /><br />A. If num is greater than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num.<br />This option is incorrect because it sets the minimum equal to num if num is greater than the minimum, which is not the correct behavior. It should set the minimum equal to num if num is less than the minimum.<br /><br />B. If num is less than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum set the maximum equal to num.<br />This option is correct. It sets the minimum equal to num if num is less than the current minimum, and it sets the maximum equal to num if num is greater than the current maximum.<br /><br />C. If num is less than the minimum, set the minimum equal to num. Otherwise, if num is less than the maximum set the maximum equal to num.<br />This option is incorrect because it sets the maximum equal to num if num is less than the maximum, which is not the correct behavior. It should set the maximum equal to num if num is greater than the maximum.<br /><br />D. If num is greater than the minimum, set the minimum equal to num. Otherwise, if num is less than the maximum, set the maximum equal to num.<br />This option is incorrect because it sets the minimum equal to num if num is greater than the minimum, which is not the correct behavior. It should set the minimum equal to num if num is less than the minimum.<br /><br />Therefore, the correct answer is B.
Haz clic para calificar: