ProgrammingModerateLTIMindtree · Cognizant GenC
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer a[5] = {3, 8, 2, 7, 5}, i, total = 0, s = 0
for (i = 0; i < 5; i = i + 1)
total = total + a[i]
end for
for (i = 0; i < 5; i = i + 1)
if (a[i] * 5 > total)
s = s + a[i]
end if
end for
Print s- A. 20
- B. 15
- C. 23
- D. 8
Correct answer: B. 15
total = 25, so a[i] * 5 > 25 means a[i] > 5; the elements 8 and 7 give 15.
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? String s = "education" Integer i, c = 0 for (i = 0; i < length(s); i = i + 1) if…
- What will be the output of the following pseudocode? Function f(Integer n) if (n <= 1) return 1 end if return f(n - 1) + f(n - 2) end…
- What will be the output of the following pseudocode? Integer x = 1, i for (i = 1; i <= 5; i = i + 1) x = (x 3) mod 7 end for Print x
- What will be the output of the following pseudocode? Integer i, s = 0 for (i = 1; i <= 10; i = i + 1) if (i mod 3 == 0) continue end if if…
- What will be the output of the following pseudocode? Integer n = 4021, r = 0 while (n > 0) r = r 10 + (n mod 10) n = n / 10 end while…
- What will be the output of the following pseudocode? Procedure p(Integer a[], Integer x) a[0] = a[0] + x x = x + 100 a[1] = x return x end…