ProgrammingEasyCapgemini · Infosys pattern
What will be the output of the following pseudocode? (Arrays are indexed from 0.)
What will be the output of the following pseudocode? (Arrays are indexed from 0.)
Integer arr[4] = {4, 9, 2, 7}
Integer m = arr[0]
for (each i from 1 to 3)
if (arr[i] > m)
m = arr[i]
end if
end for
Print m- A. 9
- B. 4
- C. 2
- D. 7
Correct answer: A. 9
This is a running maximum: m goes 4 → 9 and stays 9 because 2 and 7 are smaller.
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? Integer x = 10 if (x > 5) x = x 2 else x = x + 2 end if if (x > 15) x = x - 3 end if…
- What will be the output of the following pseudocode? Integer c = 0 for (each i from 1 to 20) if (i mod 3 == 0 or i mod 5 == 0) c = c + 1…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer n = 4521, r = 0 while…
- 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…
- What will be the output of the following pseudocode? Integer c = 0 for (each i from 1 to 4) for (each j from i to 4) c = c + 1 end for end…