ProgrammingHardTCS NQT · Cognizant GenC Next
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Function sd(Integer n)
Integer s = 0
for (each d from 1 to n - 1)
if (n mod d == 0)
s = s + d
end if
end for
return s
End Function
Integer a = 220, b = sd(a)
Print b, sd(b) == a- A. 220 true
- B. 284 false
- C. 504 false
- D. 284 true
Correct answer: D. 284 true
The proper divisors of 220 add to 284, and those of 284 (1 + 2 + 4 + 71 + 142) add back to 220. So 220 and 284 are an amicable pair: 284 true.
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? (All variables are integers, so / is integer division; + joins strings) String digits…
- What will be the output of the following pseudocode? (code(c) gives a letter's character code and char(k) the reverse) String s =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; arrays are indexed from 0)…
- What will be the output of the following pseudocode? Integer c = 0 for (each i from 1 to 10) for (each j from 1 to i) if (j j > i) break…
- What will be the output of the following pseudocode? Integer m[3][3] = {{5, 1, 7}, {2, 9, 3}, {8, 4, 6}} Integer c = 0 Boolean peak for…
- What will be the output of the following pseudocode? String s = "CODE IS FUN", r = "", w = "" for (each i from 0 to length(s) - 1) if…