ProgrammingHardTCS NQT · Infosys
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer c = 0
for (each y from 1890 to 2010)
if ((y mod 4 == 0 AND y mod 100 != 0) OR y mod 400 == 0)
c = c + 1
end if
end for
Print c- A. 30
- B. 31
- C. 28
- D. 29
Correct answer: D. 29
Multiples of 4 from 1892 to 2008: (2008 − 1892)/4 + 1 = 30; 1900 fails the century rule, 2000 passes it (divisible by 400), so 29. 30 ignores the century rule, 28 also drops 2000, and 31 is (2010 − 1890)/4 + 1, wrongly treating 1890 as a leap year.
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? (AND has higher precedence than OR) Integer a = 5, b = 2, c = 3 if (a > b OR b > c…
- What will be the output of the following pseudocode? Integer calls = 0 Function f(Integer m, Integer n) calls = calls + 1 if (m == 0 OR n…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer a = 1, b = 100, steps…
- What will be the output of the following pseudocode? Integer a[5] = {7, 7, 5, 7, 6} Integer m1 = -1, m2 = -1 for (each i from 0 to 4) if…
- What will be the output of the following pseudocode? Integer a[5] = {2, 3, 4, 5, 1}, passes = 0, n = 5 Boolean swapped for (each i from 0…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 77, steps = 0, p…