ISRO Computer Science (CSE) 2008 - Question 43

All ISRO Computer Science (CSE) papers | ISRO Computer Science (CSE) 2008

What is printed as a result of executing the code segment? for(int k=0; k<20; k=k+2) { if(k%3 == 1) print(k + " "); }

  • A. 4 16
  • B. 4 10 16
  • C. 0 6 12 18
  • D. 1 4 7 10 13 16 19

Answer: B. 4 10 16

Explanation: k takes values 0, 2, 4, 6, 8, 10, 12, 14, 16, 18. k%3==1 checks: 0(0), 2(2), 4(1)-Print, 6(0), 8(2), 10(1)-Print, 12(0), 14(2), 16(1)-Print, 18(0). Prints: 4 10 16.

| | All questions of ISRO Computer Science (CSE) 2008