ProgrammingVery hardAmazon OA · Infosys SP
What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
Integer n = 36, s = 0
for (each i from 1 to n)
if (i * i > n)
break
end if
if (n mod i == 0)
s = s + i + n / i
end if
end for
Print s- A. 91
- B. 97
- C. 85
- D. 55
Correct answer: B. 97
Pairing divisors i and n / i up to √n is fast, but for i = 6 both members of the pair are 6, so it is added twice. The true divisor sum of 36 is 91; the code prints 97.
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? (& is bitwise AND) Integer mask = 13, s, c = 0 s = mask while (s > 0) c = c + 1 s =…
- What will be the output of the following pseudocode? (integers are 32-bit; & is AND, << and >> are shifts) Integer x = 45 Integer y = (x…
- What will be the output of the following pseudocode? // BST: smaller keys go left, larger (or equal) keys go right Insert into an empty…
- What will be the output of the following pseudocode? Insert into an empty BST, in this order: 8, 3, 10, 1, 6, 14, 4, 7, 13 Queue q =…
- What will be the output of the following pseudocode? (Print writes its values on one line, separated by spaces) Integer burst[3] = {5, 3…
- What will be the output of the following pseudocode? Integer g[4][4] = {{0,0,0,0}, {0,1,0,0}, {0,0,0,1}, {1,0,0,0}} // 1 = blocked Integer…