ProgrammingModerateAccenture · Cognizant pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer x = 7, y = 3 Print x mod y * y + x / y
- A. 5
- B. 3
- C. 8
- D. 9
Correct answer: A. 5
mod, * and / share the same precedence and are worked left to right: (7 mod 3) × 3 = 3, then 7 / 3 = 2 with integer division, so 3 + 2 = 5. Reading it as 7 mod (3 × 3) gives 7 + 2 = 9.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[6] = {1, 2, 3, 4, 5, 6} for (each i from 0…
- How many times is fun called in total when fun(6) is evaluated? Function fun(Integer n) if (n <= 2) return 1 end if return fun(n - 1) +…
- What will be the output of the following pseudocode? Integer c = 0, j for (each i from 1 to 10) j = i while (j <= 10) c = c + 1 j = j + i…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- How many numbers are printed when fun(5) is called? Function fun(Integer n) if (n <= 0) return end if fun(n - 1) Print n fun(n - 2) End…