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
- A. 3
- B. 7
- C. 1
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The number of ways to write 20 as p + q with p and q prime and p <= q is counted by the procedure below, which tries p = 2 to 10 and sets…
- For n = 1 to 100, the procedure below counts how many n satisfy that nn ends with the digit 1. What is printed? count = 0 for n = 1 to 100…
- 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…