Which of the following correctly displays the lowest value in myArray? Constant
ID: 3761633 • Letter: W
Question
Which of the following correctly displays the lowest value in myArray?
Constant Integer SIZE= 30
Declare Integer index
Declare Real lowValue
Declare Real myArray[SIZE]
Set lowValue = myArray[0]
For index = 1 To SIZE-1
If myArray[index] < lowValue Then
Set lowValue = myArray[index]
End If
End For
Display lowValue
Set lowValue = myArray[0]
For index = lowValue To SIZE
If myArray[index] < lowValue Then
Set lowValue = myArray[index]
End If
End For
Display lowValue
Set lowValue = myArray[0]
For index = 1 To SIZE-1
If myArray[index] >= lowValue Then
Set lowValue = myArray[index]
End If
End For
Display lowValue
Set lowValue = myArray[0]
For index = 1 To SIZE-1
If myArray[index] > lowValue Then
Set lowValue = myArray[index]
End If
End For
Display lowValue
a.Set lowValue = myArray[0]
For index = 1 To SIZE-1
If myArray[index] < lowValue Then
Set lowValue = myArray[index]
End If
End For
Display lowValue
b.Set lowValue = myArray[0]
For index = lowValue To SIZE
If myArray[index] < lowValue Then
Set lowValue = myArray[index]
End If
End For
Display lowValue
c.Set lowValue = myArray[0]
For index = 1 To SIZE-1
If myArray[index] >= lowValue Then
Set lowValue = myArray[index]
End If
End For
Display lowValue
d.Set lowValue = myArray[0]
For index = 1 To SIZE-1
If myArray[index] > lowValue Then
Set lowValue = myArray[index]
End If
End For
Display lowValue
Explanation / Answer
a is the answer.
The logic goes like this.
1. Initially assume the first value in the array myArray[0] as lowvalue.
2. Then starting from the second value till the last value, compare every value in the array to the lowvalue, which we assumed. If any of the array is lower than the lowvalue(we will update our assumption), assign the new array value to lowvalue.
3. By the time you reach the end of array, the lowvalue will hold the lowest value.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.