Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following pseudocode processes the elements in an array using a loop. there

ID: 664904 • Letter: T

Question

The following pseudocode processes the elements in an array using a loop. there is no input to this program.

1 Constant Integer DECL = 10

2 Declare Integer numNums[DECL] = 15, 6, 7, 15, 3, 9, 12, 19, 8, 2

3 Declare Integer a1, a2, label, apart

4

5 Set a1 = 0

6 Set a2 = 1

7 Set label = 1

8

9 While a1 <= DECL - 1 AND a2 <= DECL - 1

10         If numNums[a1] > numNums[a2] <= DECL - 1

11                    Set apart = numNums[a2] Then

12          Else

13                    Set apart = numNums[a2] - numNums[a1]

14          End If

15

16          Display "Value #", label, ": ", apart

17

18          Set a1 = a1 + 2

19          Set a2 = a2 + 2

20          Set label = label + 1

21 End While

Trace the execution of this program, and determine what output the program produces (that is, every line of output that appears on the screen when you run this program). You are not required to demonstrate your work (how you arrived at your solution), but you may want to use a piece of paper to trace the changes in the variables..

WARNING: Don't describe everything that happens in the program. Your solution should contain only what the user would see on the screen when running the program.

Explanation / Answer

This program is basically checking the numbers and is doing some calculation on it.

line no 10 first condition will be

15>6

so it will set apart = 6

so the first print statement will give Value#1:6

now it will take 7 and 15

7>15 no so else part

it will get 15-7 = 8

then it will print Value#2:8

3>9 no

it will 9-3 = 6

then it will print Value#3:6

12>19 no

then it will print Value#4:7

8>2 yes

then it will print Value#5:8