ProgrammingEasyInfosys · Capgemini pattern
What will be the output of the following pseudocode? (/ is integer division.)
What will be the output of the following pseudocode? (/ is integer division.)
Integer n = 2405, c = 0, s = 0
while (n > 0)
s = s + n mod 10
c = c + 1
n = n / 10
end while
Print c, s- A. 3 11
- B. 4 9
- C. 4 11
- D. 4 5042
Correct answer: C. 4 11
Each pass peels off the last digit: 5, 0, 4, 2 → c = 4 digits (the 0 still counts as a digit) and s = 5 + 0 + 4 + 2 = 11. '3' skips the zero digit; 5042 is the reversed number, which this code never builds.
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? Integer c = 0 for (i = 1 to 4) for (j = 1 to 4) if (j > i) break end if c = c + j end…
- What will be the output of the following pseudocode? (&, |, ^ are bitwise AND, OR, XOR; << is a left shift; precedence as in C: << binds…
- What will be the output of the following pseudocode? Function f(Integer n) if (n <= 1) return 1 end if return f(n - 1) + 2 f(n - 2) End…
- What will be the output of the following pseudocode? (Strings are indexed from 0.) String s = "PSEUDOCODE" Integer v = 0 for (i = 0 to…
- What will be the output of the following pseudocode? Integer x = 1 for (k = 1 to 10) x = (x 3) mod 7 end for Print x
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[5] = {3, 1, 4, 1, 5} for (i = 1 to 4) arr[i]…