Question 21
EasyWhat will be the output of the following pseudocode?
Function area(Integer l, Integer w)
return l * w
End Function
Function perimeter(Integer l, Integer w)
return 2 * (l + w)
End Function
Print area(3, 4) + perimeter(3, 4)
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 area(Integer l, Integer w)
return l * w
End Function
Function perimeter(Integer l, Integer w)
return 2 * (l + w)
End Function
Print area(3, 4) + perimeter(3, 4)
14
26
24
12
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Function steps(Integer n)
if (n == 1)
return 0
end if
if (n mod 2 == 0)
return 1 + steps(n / 2)
end if
return 1 + steps(3 * n + 1)
End Function
Print steps(6)
8
16
5
6
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Function twice(Integer x)
return 2 * x
End Function
Print twice(twice(twice(1)))
3
8
6
2
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Function countDown(Integer n)
if (n == 0)
return 0
end if
return 1 + countDown(n - 1)
End Function
Print countDown(5)
5
15
0
6
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function avg(Integer a, Integer b, Integer c)
return (a + b + c) / 3
End Function
Print avg(4, 8, 9)
6
7.0
21
7
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Function join(Integer a, Integer b)
return a * 10 + b
End Function
Print join(join(1, 2), 3)
15
6
33
123
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Function digitSum(Integer n)
if (n == 0)
return 0
end if
return n mod 10 + digitSum(n / 10)
End Function
Function root(Integer n)
if (n < 10)
return n
end if
return root(digitSum(n))
End Function
Print root(9875)
9
29
11
2
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 < 2)
return n
end if
return f(n - 1) + f(n - 2)
End Function
Print f(7)
7
21
8
13
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function g(Integer n)
if (n <= 0)
return 0
end if
return n + g(n - 2)
End Function
Print g(9)
45
20
25
9
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Function b(Integer n)
if (n == 0)
return ""
end if
return b(n / 2) + toString(n mod 2) // integer division
End Function
Print b(13)
1011
1101
13
0110
Sign up free to see the answer and a step-by-step explanation.