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
  1. A. 20
  2. B. 19
  3. C. 4
  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.

More Pseudocode and Code Tracing questions

Exams that ask this topic