ProgrammingHardAccenture · Cognizant pattern
What will be the output of the following pseudocode (maximum product of any two elements)? (Arrays are indexed from 0.)
What will be the output of the following pseudocode (maximum product of any two elements)? (Arrays are indexed from 0.)
Integer arr[8] = {3, -1, 4, 1, 5, 9, 2, 6}
sort arr ascending
Integer n = length(arr)
Print arr[n - 1] * arr[n - 2]- A. 45
- B. 54
- C. 56
- D. 63
Correct answer: B. 54
After sorting ascending, the two largest elements are 9 and 6 (the last two positions), and their product is 9*6=54.
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 (counting words longer than the average word length)? List words = {"the", "quick"…
- 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…