23.2k views
2 votes
What is the first output corresponding to the following pseudocode? The first line of output displays the value _________. (Note: if there are any spaces, it is assumed to be one space.) Declare N As Integer Declare K As Integer Declare X[100] As Integer Set N = 4 Set K = 1 While K <= N Set X[K] = K^2 Set K = K + 1 End While Write X[N/2] Write X[1] + " " + X[N - 1]

User Braunbaer
by
5.9k points

1 Answer

4 votes

Answer:

4

Step-by-step explanation:

Initially the values are N = 4 and K = 1

k=1:

While 1 <= 4 // true

X[1] = 1^2 =1

K = 1 + 1 =2

k=2:

While 2 <= 4 // true

X[2] = 2^2 =4

K = 2 + 1 = 3

k=3:

While 3 <= 4 // true

X[2] = 3^2 =9

K = 3 + 1 = 4

k=4:

While 4 <= 4 // true

X[2] = 4^2 =16

K = 4 + 1 = 5

k=5:

While 5 <= 4 // false

End While

Write X[4/2] => X[2] = 4

Write X[1] + " " + X[4 - 1]

Write X[1] + " " + X[3] // here x[1] = 1 and x[3] = 9 it print 1 9

Output:

4

1 9

The first line of output displays the value 4.

User Murtaza Munshi
by
5.5k points