ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains
The procedure below counts the integers from 1 to 29 that are divisible by 3 or by 5. What is printed?
The procedure below counts the integers from 1 to 29 that are divisible by 3 or by 5. What is printed?
count = 0
for n = 1 to 29
if n mod 3 == 0 or n mod 5 == 0 then count = count + 1
end for
Print count- A. 13
- B. 14
- C. 9
- D. 5
Correct answer: A. 13
Multiples of 3 below 30 are 9 numbers, multiples of 5 are 5 numbers, and 15 is counted in both, so 9 + 5 - 1 = 13. Including 30 gives 14, the multiples of 3 alone give 9, and the multiples of 5 alone give 5.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- Read the pseudocode. a = 1, b = 1, s = 0 for i = 1 to 6 t = a + b a = b b = t if (t mod 3 == 0) s = s + t else s = s - 1 end for print s…
- Consider the function. f(n): if n <= 1 return n if n mod 2 == 0 return f(n / 2) + 1 return 2 f(n - 1) + 1 What is f(13)?
- Consider the pseudocode. sum = 0 for i = 1 to 15: n = i while n != 0: n = n AND (n - 1) sum = sum + 1 print sum What is printed?
- Consider the pseudocode. s = 0 for i = 1 to 7: if i mod 3 == 0: continue j = i while j > 0: if j mod 4 == 0: break s = s + j j = j - 2…
- Consider the pseudocode. global calls = 0 f(n): calls = calls + 1 if n <= 2 return n return f(n - 1) + f(n - 3) r = f(7) print r, calls…
- Integers are passed by value and arrays by reference (the reference itself is copied). g(a, x): a[0] = a[0] + x x = x 2 a = [9, 9] a[1] =…