ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains
A number's digit sum is computed by the procedure below for N = 98765. What is printed?
A number's digit sum is computed by the procedure below for N = 98765. What is printed?
s = 0; m = N
while m > 0
s = s + (m mod 10)
m = m div 10
end while
Print s- A. 5
- B. 15120
- C. 56789
- D. 35
Correct answer: D. 35
Adding the digits 9 + 8 + 7 + 6 + 5 gives 35. The digit count is 5, the product of the digits is 15120, and the reverse of the number is 56789.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The procedure below uses the sieve of Eratosthenes on the range 2 to 50, marking composites starting from ii. The inner marking statement…
- Compute 3^13 mod 7 with the binary method below (a = 3, e = 13, m = 7). What is printed? result = 1; base = a mod m; e = 13 while e > 0 if…
- Let phi(n) be the number of integers i with 1 <= i <= n that share no common factor with n except 1. The procedure below computes phi(36)…
- Starting from n = 27, the Collatz step is applied: if n is even, n becomes n/2, otherwise n becomes 3n + 1. The procedure below counts the…
- Four numbers 4, 6, 10 and 15 are combined pairwise: the lcm of a and b is computed as ab div gcd(a, b), and the lcm of three numbers is…
- Count the integers n with 1 <= n <= 100 that are divisible by 3 or by 5, but NOT by both. The procedure below does this with a single…