ProgrammingModerateTCS NQT · Wipro
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)
Integer n = 7086351, s = 0, d
while (n > 0)
d = n mod 10
if (d mod 2 == 1)
s = s + d
end if
n = n / 10
end while
Print s- A. 16
- B. 30
- C. 14
- D. 17
Correct answer: A. 16
The loop adds only the odd digits of 7086351: 7 + 3 + 5 + 1 = 16. Adding all digits gives 30.
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? Procedure upd(Integer arr[], Integer n) // arrays are passed by reference arr[0] =…
- What will be the output of the following pseudocode? (& is bitwise AND) Integer x = 255, y = 256, c1 = 0, c2 = 0 while (x > 0) x = x & (x…
- What will be the output of the following pseudocode? Integer cnt = 0 Procedure go(Integer i, Integer s) if (s == 10) cnt = cnt + 1 return…
- What will be the output of the following pseudocode? Function G(Integer n) if (n == 0) return 0 end if return n - G(G(n - 1)) End Function…
- What will be the output of the following pseudocode? (code(c) gives a letter's character code; 'A' to 'Z' have consecutive codes) String w…
- What will be the output of the following pseudocode? (stop ends the program; arrays are indexed from 0) Integer a[6] = {3, 4, 5, 6, 1, 8}…