ProgrammingHardCapgemini · Infosys pattern
What will be the output of the following pseudocode (counting words longer than the average word length)?
What will be the output of the following pseudocode (counting words longer than the average word length)?
List words = {"the", "quick", "brown", "fox", "jumps"}
Real avg = averageLength(words)
Integer c = 0
for (each w in words)
if (length(w) > avg)
c = c + 1
end if
end for
Print c- A. 2
- B. 4
- C. 3
- D. 5
Correct answer: C. 3
Word lengths are 3,5,5,3,5, averaging 21/5=4.2. Words longer than 4.2 are 'quick'(5), 'brown'(5), 'jumps'(5) -- three words.
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 (grouping anagrams together and counting the groups)? List words = {"eat", "tea"…
- What will be the output of the following pseudocode (a do-while-style loop that always runs at least once)? Integer x = 10, c = 0 repeat x…
- What will be the output of the following pseudocode (searching a 2D array, stopping both loops once found)? (Arrays are indexed from 0.)…
- What will be the output of the following pseudocode (finding the missing number from 1..n)? (Arrays are indexed from 0.) Integer arr[5] =…
- What will be the output of the following pseudocode (checking whether an array is sorted in non-decreasing order)? (Arrays are indexed…
- What will be the output of the following pseudocode (summing a range with a step)? Function sumRange(Integer a, Integer b, Integer step)…