Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

ISRO | ISRO CS 2013 | Question 62

  • Last Updated : 15 May, 2018

Consider the following C code.
#include

#include 
void main()
{
 double pi = 3.1415926535;
 int a = 1;
 int i;
 for(i=0; i < 3; i++)
 if(a = cos(pi * i/2) )
 printf("%d ",1);
 else printf("%d ", 0);
}

What 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: 101

Option (C) is correct.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :