ProgrammingModerateTCS NQT · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Function odd(Integer n)
if (n == 0)
return 0
end if
return odd(n - 1) + 2 * n - 1
End Function
Print odd(12)- A. 156
- B. 78
- C. 144
- D. 169
Correct answer: C. 144
odd(n) adds the first n odd numbers 1 + 3 + … + (2n − 1), which equals n². odd(12) = 144.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? ((mask >> i) & 1 is evaluated before ==; ^ is XOR) Integer a[3] = {5, 1, 6}, total =…
- What will be the output of the following pseudocode? (+ joins strings) String s = "PAYPALISHIRING" Integer rows = 3, r = 0, step = 1…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[5] = {1, 3, 5, 4, 2}, n = 5 Integer i = n - 2…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[9] = {3, 2, 3, 1, 2, 4, 5, 5, 6}, k = 4 sort a…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Function canSplit(Integer a[]…
- What will be the output of the following pseudocode? Integer g[3][3] = {{1, 3, 1}, {1, 5, 1}, {4, 2, 1}} for (each i from 0 to 2) for…