ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains
For n = 1 to 100, the procedure below counts how many n satisfy that nn ends with the digit 1. What is printed?
For n = 1 to 100, the procedure below counts how many n satisfy that n*n ends with the digit 1. What is printed?
count = 0
for n = 1 to 100
if (n * n) mod 10 == 1 then count = count + 1
end for
Print count- A. 20
- B. 19
- C. 4
- D. 10
Correct answer: A. 20
A square ends in 1 exactly when n ends in 1 or 9, which gives 20 values from 1 to 100. Skipping n = 1 gives 19, testing the last two digits gives 4, and testing for a square ending in 0 gives 10.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The array a = [2, 3, 4, 1, 2, 3, 9] is scanned for its longest run of consecutive positions where each element is exactly one more than…
- The stack-based procedure below computes, for each index i of a = [4, 2, 6, 1, 5], the index of the next greater element to its right (or…
- An array a = [1, 3, 5, 7, 9, 11, 13, 15] is searched with binary search for the target 15, and the procedure counts how many array…
- The procedure below converts the Roman numeral "MCMXCIV" to a number by reading left to right and subtracting a symbol's value when the…
- A recursive function is written as below. The procedure counts the calls made for input 7, including the first call. What is printed?…
- The procedure below uses exponentiation by squaring on the exponent 37. It counts one multiplication into result each time the current…