Assume that the first element in the array has the address of 1. Answer each of
ID: 3685287 • Letter: A
Question
Assume that the first element in the array has the address of 1. Answer each of the following questions based on the given pseudocode for a program as shown below,
module main( )
Declare Integer SIZE = 5
Declare Integer index = 1
Declare Integer x = 0
Declare Integer y = 0
Declare Integer num[SIZE] = 10, -13, 17, 21, 65
Set x = num[index]
While ( index <= SIZE )
IF (num[index) <= x ) Then
Set x = num[index]
End If
Set index = index + 1
End While
Set index = 1
Set y = num[index]
While ( index <= SIZE )
IF (num[index) >= y ) Then
Set y = num[index]
End If
Set index = index + 1
End While
End module
QUESTION 1
The element num[3] has the value of
10 points
QUESTION 2
After the completion of the execution of this code, the value of the variable x is
20 points
QUESTION 3
After the completion of executing the code, the value of the variable y is
20 points
QUESTION 4
The index of the last element in the array is
20 points
QUESTION 5
The data 12.5 can be assigned to the element num[2].
True
False
10 points
QUESTION 6
The value of the variable index after executing the While looping structure is
Assume that the first element in the array has the address of 1. Answer each of the following questions based on the given pseudocode for a program as shown below,
module main( )
Declare Integer SIZE = 5
Declare Integer index = 1
Declare Integer x = 0
Declare Integer y = 0
Declare Integer num[SIZE] = 10, -13, 17, 21, 65
Set x = num[index]
While ( index <= SIZE )
IF (num[index) <= x ) Then
Set x = num[index]
End If
Set index = index + 1
End While
Set index = 1
Set y = num[index]
While ( index <= SIZE )
IF (num[index) >= y ) Then
Set y = num[index]
End If
Set index = index + 1
End While
End module
Explanation / Answer
module main( )
Declare Integer SIZE = 5 //Declares SIZE as 5.
Declare Integer index = 1 //Declares index and initializes to 1.
Declare Integer x = 0 //Declares x and initializes to 0.
Declare Integer y = 0 //Declares y and initializes to 0.
Declare Integer num[SIZE] = 10, -13, 17, 21, 65 //Declares num an array, and initializes with given values.
Set x = num[index] //Sets x as num[index], i.e., x will hold the value 10.
While ( index <= SIZE ) //For each element in the array.
IF (num[index) <= x ) Then //If that element is less than or equal to x,
Set x = num[index] //Set that element to x.
End If
Set index = index + 1 //Move to the next element.
End While
Set index = 1 //Set index back to 1.
Set y = num[index] //Sets y as num[index], i.e., y will hold the value 10.
While ( index <= SIZE ) //For each element in the array.
IF (num[index) >= y ) Then //If that element is greater than or equal to x,
Set y = num[index] //Set that element to y.
End If
Set index = index + 1 //Move to the next element.
End While
End module
//Here the assumption is that, array index starts with 1, and will go upto 5.
//Simply speaking this algorithm, finds the smallest element in the array, and will assign to x,
//and will find the largest element in the array, and will assign to y.
QUESTION 1
The element num[3] has the value of 17.
10 points
QUESTION 2
After the completion of the execution of this code, the value of the variable x is -13.
20 points
QUESTION 3
After the completion of executing the code, the value of the variable y is 65.
20 points
QUESTION 4
The index of the last element in the array is 5.
20 points
QUESTION 5
The data 12.5 can be assigned to the element num[2]. False.
True
False
10 points
QUESTION 6
The value of the variable index after executing the While looping structure is 6.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.