ProgrammingModerateTCS NQT · Wipro
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer s = 0
for (each i from 1 to 49)
if (i mod 3 == 0 OR i mod 5 == 0)
s = s + i
end if
end for
Print s- A. 543
- B. 651
- C. 618
- D. 593
Correct answer: A. 543
Multiples of 3 below 50 add to 3 × (1 + … + 16) = 408, multiples of 5 to 5 × (1 + … + 9) = 225, and multiples of 15 (counted twice) to 15 + 30 + 45 = 90. 408 + 225 − 90 = 543.
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 OR, & is AND, << and >> are shifts) Integer c = 0, r, x for (each n from 1 to…
- What will be the output of the following pseudocode? Function iso(String a, String b) Map f = empty, g = empty for (each i from 0 to…
- What will be the output of the following pseudocode? (strings are indexed from 0) String s = "AEBCBDA" String t = reverse of s Integer n =…
- What will be the output of the following pseudocode? Integer p[6] = {7, 1, 5, 3, 6, 4} Integer lo = p[0], one = 0, many = 0 for (each i…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[5] = {2, 3, 1, 1, 4} Integer jumps = 0, curEnd…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer h[9] = {1, 8, 6, 2, 5, 4, 8, 3, 7} Integer i = 0…