Question 31
MediumWhat will be the output of the following pseudocode?
Function g(Integer a, Integer b)
if (b == 0)
return a
end if
return g(b, a mod b)
End Function
Print g(84, 36)
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 will be the output of the following pseudocode?
Function g(Integer a, Integer b)
if (b == 0)
return a
end if
return g(b, a mod b)
End Function
Print g(84, 36)
4
6
12
36
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Integer calls = 0
Function c(Integer n)
calls = calls + 1
if (n <= 0)
return 0
end if
return c(n - 1) + c(n - 2)
End Function
c(4)
Print calls
4
9
8
15
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function r(Integer n)
if (n == 0)
return ""
end if
return toString(n) + r(n - 1) + toString(n)
End Function
Print r(3)
3213
123321
321123
333
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function modify(Integer arr[])
arr[0] = 100
End Function
Integer a[] = {1, 2, 3}
modify(a)
Print a[0]
1
100
Error
0
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Function f(Integer n)
if (n <= 1)
return 1
end if
return n * f(n - 2)
End Function
Print f(7)
105
5040
15
48
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Function g(Integer a, Integer b)
if (b == 0)
return 1
end if
return a * g(a, b - 1)
End Function
Print g(3, 4)
12
81
27
64
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Function s(Integer n)
if (n == 0)
return 0
end if
return (n mod 10) + s(n / 10)
End Function
Print s(s(9875))
11
29
2
20
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Function h(Integer n)
if (n == 0)
return
end if
Print n
h(n - 1)
Print n
End Function
h(3)
1 2 3 3 2 1
3 2 1
3 2 1 1 2 3
3 3 2 2 1 1
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function fib(Integer n)
if (n < 2)
return n
end if
return fib(n - 1) + fib(n - 2)
End Function
Integer i
for (each i from 5 to 8)
Print fib(i)
end for
5 8 13 21
5 8 12 20
3 5 8 13
8 13 21 34
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Function bin(Integer n)
if (n == 0)
return ""
end if
return bin(n / 2) + (n mod 2)
End Function
Print bin(19)
11001
19
10011
10101
Sign up free to see the answer and a step-by-step explanation.