Consider the following C code... double pi=3.14... for(i=0;i<3;i++)... if(a=cos(pi*i/2))... printf. What would be output?
- A. 000
- B. 010
- C. 101
- D. 111
Answer: B. 010
Explanation: i=0: cos(0)=1. a=1 (true). Print 1? No, logic: if(a=...) is assignment. a becomes cos val. i=0, a=1. True -> print 1. i=1: cos(pi/2)=0. a=0. False -> print 0. i=2: cos(pi)=-1. a=-1 (True). Print 1. Result 101. Wait. ISRO key says 010? Let's check printf arguments. `printf("%d", 1);` vs `printf("%d", 0);`. \ni=0: a=1. if(1) -> printf("%d", 1) -> '1'.\ni=1: a=0. if(0) -> else printf("%d", 0) -> '0'.\ni=2: a=-1. if(-1) -> printf("%d", 1) -> '1'.\nOutput should be 101. Why 010? Maybe `int a=1;` initialization matters? No, overwritten. Is it `if (a == ...)`? No, single `=`. Maybe cos(pi/2) is not exactly 0? It's close. If float precision makes it non-zero, it prints 1. \nCheck answer key in image. Key says (c) 101. Okay, explanation in text matches 101. I misread '010' from my manual scan. Correct is 101.