ProgrammingHardCapgemini · Infosys pattern
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 = 100, c = 0, d = 5
while (d <= n)
c = c + n / d
d = d * 5
end while
Print c- A. 22
- B. 20
- C. 24
- D. 25
Correct answer: C. 24
This is Legendre's count of the factor 5 in 100!, which is the number of trailing zeros: 100 / 5 + 100 / 25 = 20 + 4 = 24 (125 > 100 stops the loop). Counting only multiples of 5 gives 20.
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? (calls counts every call, including the first.) Integer calls = 0 Function fun(Integer a, Integer b) calls =…
- What will be the output of the following pseudocode? Integer c = 0 for (i = 1; i < 64; i = i 2) for (j = i; j < 64; j = j + i) c = c + 1…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[4] = {2, 3, 1, 0} for (each i from 0 to 3)…
- What will be the output of the following pseudocode? Function f(Integer n) if (n > 100) return n - 10 end if return f(f(n + 11)) End…