Question 51
MediumWhat is the output of this pseudocode?
Function m(Integer a, Integer b)
if (a == 0)
return 0
end if
return b + m(a - 1, b)
End Function
Print m(6, 7)
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Pseudocode and Output Prediction
What is the output of this pseudocode?
Function m(Integer a, Integer b)
if (a == 0)
return 0
end if
return b + m(a - 1, b)
End Function
Print m(6, 7)
13
42
36
49
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Function hanoi(Integer n)
if (n == 0)
return 0
end if
return 2 * hanoi(n - 1) + 1
End Function
Print hanoi(5)
31
32
16
25
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function f(Integer n)
if (n == 1)
return 0
end if
if (n mod 2 == 0)
return 1 + f(n / 2)
end if
return 1 + f(n - 1)
End Function
Print f(15)
6
7
5
4
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Function c(Integer n, Integer r)
if (r == 0 or r == n)
return 1
end if
return c(n - 1, r - 1) + c(n - 1, r)
End Function
Print c(7, 3)
35
21
210
28
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function A(Integer m, Integer n)
if (m == 0)
return n + 1
end if
if (n == 0)
return A(m - 1, 1)
end if
return A(m - 1, A(m, n - 1))
End Function
Print A(2, 2)
4
5
6
7
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function M(Integer n)
if (n > 100)
return n - 10
end if
return M(M(n + 11))
End Function
Print M(87)
87
98
91
77
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function f(Integer n)
if (n == 1)
return 1
end if
return 1 + f(n / 2) // integer division
End Function
Print f(100)
50
8
6
7
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function f(Integer n)
if (n == 0)
return 0
end if
return (n mod 2) + f(n / 2) // integer division
End Function
Print f(255) - f(256)
8
0
7
-1
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function t(Integer n)
if (n > 0)
t(n - 1)
Print n
t(n - 1)
end if
End Function
t(3)
3 2 1 1 2 3
1 2 3 3 2 1
1 1 2 1 1 3
1 2 1 3 1 2 1
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function f(Integer n)
if (n <= 0)
return 0
end if
return f(n - 3) + n
End Function
Print f(10)
22
10
18
55
Sign up free to see the answer and a step-by-step explanation.