20.8k views
0 votes
For the given pseudocode, which XXX and YYY will output the smallest non-negative input (stopping when a negative value is input)? Choices are in the form XXX / YYY.

min = 0
val = Get next input
min = val


While val is not negative
If XXX
YYY
val = Get next input


Put min to output

1 Answer

4 votes

Answer:

To determine the correct answer for XXX / YYY, we need to look at the purpose of the code. The goal is to find the smallest non-negative input, and stop if a negative value is input. Therefore, XXX needs to be a condition that checks if the current input is smaller than the current minimum value. YYY needs to be an action that assigns the current input value to the minimum value variable (min), if the condition is true.

One possible correct answer for XXX / YYY is "val < min / min = val". This checks if the current input value is less than the current minimum value, and if so, updates the minimum value variable to the current input value.

Another possible correct answer for XXX / YYY is "val < min / min := val". This is equivalent to the previous answer, but uses the assignment operator (:=) instead of the equals sign (=) to update the minimum value variable.

Therefore, the finalized pseudocode may look like this:

min = 0

val = Get next input

min = val

While val is not negative

If val < min

min := val

val = Get next input

Put min to output

User Mauro Sala
by
8.2k points