ProgrammingModerateTCS NQT · Accenture pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer p = 1
for (each i from 1 to 10)
p = (p * 3) mod 7
end for
Print p- A. 4
- B. 5
- C. 3
- D. 1
Correct answer: A. 4
p = 3¹⁰ mod 7. Powers of 3 mod 7 repeat every 6 (3, 2, 6, 4, 5, 1), so 3¹⁰ ≡ 3⁴ ≡ 81 mod 7 = 4.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The array holds {1, 3, 5, 7, 9, 11, 13, 15, 17} (indexed from 0). What is printed? (/ is integer division.) Integer low = 0, high = 8…
- How many swaps does this pseudocode perform? (Arrays are indexed from 0.) Integer arr[5] = {5, 1, 4, 2, 8} Integer swaps = 0 for (each i…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Function f(Integer n) if (n…
- What will be the output of the following pseudocode? Integer a = 3, b b = a a a = b - a b = b + a Print a mod b, b mod a
- How many times is count incremented? Integer n = 4, count = 0 for (each i from 1 to n) for (each j from 1 to i i) if (j mod i == 0) for…
- What will be the output? (&& does not evaluate its right side when the left side is false.) Integer c = 0, s = 0 Function inc() c = c + 1…