ProgrammingHardAccenture · Capgemini
What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
Procedure show(Integer n)
if (n == 0)
return
end if
if (n mod 2 == 1)
Print n mod 10
end if
show(n / 10)
if (n mod 2 == 0)
Print n mod 10
end if
End Procedure
show(4736)- A. 6 3 7 4
- B. 4 7 3 6
- C. 3 7 6 4
- D. 3 7 4 6
Correct answer: D. 3 7 4 6
4736 is even, so its digit 6 is printed after the recursion. 473 and 47 are odd and print 3 and 7 on the way down; 4 is even and prints after show(0). Order: 3 7 4 6.
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? (| is bitwise OR) Integer x = 0, c = 0 while (x < 1000) x = x | (x + 1) c = c + 1 end…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer arr[7] = {1, 2, 3, 4, 5, 6, 7} reverse(arr, 0, 2)…
- What will be the output of the following pseudocode? (the static s keeps its value between calls; in f(n - 1) + s the call is evaluated…
- What will be the output of the following pseudocode? Integer c = 0 for (each i from 1 to 6) for (each j from 1 to 6) if ((i j) mod 4 == 0)…
- What will be the output of the following pseudocode? (Strings are indexed from 0; + joins strings) String s = "AAABCCDAA", r = "" Integer…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Function f(Integer n) if (n ==…