Question 41
MediumWhat does the following pseudocode print?
Function count(Integer n)
if (n == 0)
return 0
end if
return count(n / 2) + 1
End Function
Print count(100)
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 does the following pseudocode print?
Function count(Integer n)
if (n == 0)
return 0
end if
return count(n / 2) + 1
End Function
Print count(100)
100
6
7
50
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Integer x = 10
Function change(Integer x)
x = x + 5
return x
End Function
Integer y = change(x)
Print x, y
15 10
10 10
15 15
10 15
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function ack(Integer m, Integer n)
if (m == 0)
return n + 1
end if
if (n == 0)
return ack(m - 1, 1)
end if
return ack(m - 1, ack(m, n - 1))
End Function
Print ack(2, 2)
5
7
4
6
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Function p(Integer n)
if (n > 0)
p(n - 1)
Print n
p(n - 1)
end if
End Function
p(2)
1 2 1
2 1
1 1 2
2 1 1
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Function gcd(Integer a, Integer b)
if (b == 0)
return a
end if
return gcd(b, a mod b)
End Function
Print gcd(84, 36) * 2, 84 * 36 / gcd(84, 36)
6 504
24 252
12 252
24 3024
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Function rev(String s)
if (length(s) <= 1)
return s
end if
return rev(substring(s, 1)) + s[0]
End Function
Print rev("code")
eodc
edoc
code
doce
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 + f(n - 3)
End Function
Print f(10)
55
21
22
18
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Integer calls = 0
Function t(Integer n)
calls = calls + 1
if (n <= 1)
return 1
end if
return t(n - 1) + t(n - 2)
End Function
Integer r = t(5)
Print r, calls
5 15
8 9
8 15
13 25
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Function sumDigitsUntilOne(Integer n)
while (n >= 10)
Integer s = 0
while (n > 0)
s = s + n mod 10
n = n / 10
end while
n = s
end while
return n
End Function
Print sumDigitsUntilOne(987654)
9
3
12
39
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Function isPal(String s, Integer i, Integer j)
if (i >= j)
return true
end if
if (s[i] != s[j])
return false
end if
return isPal(s, i + 1, j - 1)
End Function
Print isPal("level", 0, 4), isPal("lever", 0, 4)
false true
true true
false false
true false
Sign up free to see the answer and a step-by-step explanation.