ProgrammingHardTCS NQT · Accenture pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer total = 0
for (each i from 1 to 3)
for (each j from 1 to 3)
if (i <= j)
total = total + i * j
end if
end for
end for
Print total- A. 25
- B. 36
- C. 14
- D. 20
Correct answer: A. 25
Only pairs with i<=j contribute: (1,1)=1,(1,2)=2,(1,3)=3,(2,2)=4,(2,3)=6,(3,3)=9. Summing: 1+2+3+4+6+9=25.
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 (maximum product of any two elements)? (Arrays are indexed from 0.) Integer arr[8] =…
- 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] =…