ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains

The procedure below computes the last digit of 7^100 by starting from d = 1 and multiplying by 7, keeping only the last digit, once for each step of the loop. What is printed?

The procedure below computes the last digit of 7^100 by starting from d = 1 and multiplying by 7, keeping only the last digit, once for each step of the loop. What is printed?
d = 1
repeat 100 times: d = (d * 7) mod 10
Print d
  1. A. 3
  2. B. 7
  3. C. 1
  4. D. 0

Correct answer: C. 1

The last digits of powers of 7 cycle 7, 9, 3, 1 with period 4, and 100 is a multiple of 4, so the answer is 1. Running 99 or 101 steps gives 3 or 7, and starting from d = 0 never leaves 0.

More Pseudocode and Code Tracing questions

Exams that ask this topic