What will be the value of the following pseudocode for k=150?fun(integer k)if(k>155)returnend ifprint kfun(k+2)print kEnd of function fun()
Question
What will be the value of the following pseudocode for k=150?
fun(integer k)
if(k>155)
return
end if
print k
fun(k+2)
print k
End of function fun()
Solution
The pseudocode provided is a recursive function that prints the value of k
and calls itself with k+2
until k
is greater than 155. Here's how it would execute for k=150
:
- Call
fun(150)
. Since150
is not greater than155
, it will print150
and callfun(152)
. - Call
fun(152)
. Since152
is not greater than155
, it will print152
and callfun(154)
. - Call
fun(154)
. Since154
is not greater than155
, it will print154
and callfun(156)
. - Call
fun(156)
. Since156
is greater than155
, it will return and not print anything. - After each function call returns, it will print
k
again. So it will print154
,152
, and150
in that order.
So, the output of the pseudocode for k=150
will be 150, 152, 154, 154, 152, 150
.
Similar Questions
What will be the value of the following pseudocode?Integer value, n, numSet value = 1, n = 45num = num >> 1 num = num + valuePrint num
What will be the value of the following pseudocode?Integer x, yfor(each x from 1 to 11)x = x + 2end forPrint xQuestion 84AnswerA.10B.12C.13D.11
What is the output of the following pseudocode?if x > 5 thenoutput "High"elseoutput "Low"
What will be the output of the following Python code?k = 1while k < 4: print(k) k += 1else: print(1)Options1 2 31 2 3 4 1error1 2 3 1
correct answerWhat will be the output of the following Python code?def demo(x): if (x > 100): return x - 5 return demo(demo(x+11)); print(demo(45))
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.