Pseudocodes has some errors can someone please help determining what/these error
ID: 3852986 • Letter: P
Question
Pseudocodes has some errors can someone please help determining what/these errors are thank you
/ Program passes an array to a method that reverses
// the positions of the values
start
Declarations
num LENGTH = 4
num vals[LENGTH] = 33, 55, 77, 99
num sub
output "At beginning of main() method..."
sub = 0
if sub < LENGTH
output vals[sub]
sub = sub + 1
endif
reverseTheValues(vals)
output "At end of main() method.........."
sub = 0
while sub < LENGTH
output vals[sub]
sub = sub + 1
endwhile
stop
void reverseTheValues(num values)
num temp
temp = values[0]
values[0] = values[3]
temp = values[1]
values[1] = values[2]
values[2] = temp
return
Explanation / Answer
start
Declarations
num LENGTH = 4
num vals[LENGTH] = 33, 55, 77, 99
num sub
output "At beginning of main() method..."
sub = 0
while sub < LENGTH
// If loop is mostly used for selection but here we need to use the loop as it need to iterate through the list of array.
output vals[sub]
sub = sub + 1
endwhile // every loop must be ended like that while loop also ended here.
reverseTheValues(vals)
output "At end of main() method.........."
sub = 0
while sub < LENGTH
output vals[sub]
sub = sub + 1
endwhile
stop
void reverseTheValues(num[ ] values)
// Here the input parameter representing array so it must have brackets.
num temp
temp = values[0]
values[0] = values[3]
values[3] = temp
// Temp value here should be stored in values[3] otherwise the reversal of values will mixed and results wrong order.
temp = values[1]
values[1] = values[2]
values[2] = temp
return
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.