ProgrammingModerateCapgemini · Infosys pattern
What will be the output of the following pseudocode?
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
- A. 6 3
- B. 0 3
- C. 3 6
- D. 6 0
Correct answer: A. 6 3
b = 9, a = 9 - 3 = 6, b = 9 + 6 = 15. 6 mod 15 = 6, because the smaller number mod the larger is the smaller number itself, and 15 mod 6 = 3.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- 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…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- Two sorted arrays a = {1, 4, 7} and b = {2, 3, 8, 9} are merged. How many element comparisons does the pseudocode make? Integer i = 0, j =…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer c = 0, i = 16 while…