Consider the following C code.
#include
#include void main() { double pi = 3.1415926535; int a = 1; int i; for(i=0; iWhat would the program print?
(A) 000
(B) 010
(C) 101
(D) 111
Answer: (C)
Explanation: In first iteration: i = 0:
a = cos(pi * 0/2)
a = cos(0) = 1, condition true print 1
Second iteration: i = 1
a = cos (pi/2)
a = 0, so else part would print 0
Third iteration: i = 2
a = cos(pi)
a = -1, since any value other than 0
inside if statement returns true,
print 1
Output: 101Option (C) is correct.
Quiz of this Question
Article Tags :
Recommended Articles