2,060 views
0 votes
0 votes
#include<stdio.h>  
#include<math.h>  
int 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);  
}
  1. 0 0 0
  2. 0 1 0
  3. 1 0 1
  4. 1 1 1

2 Answers

0 votes
0 votes
ans is C) 1 0 1 now sure :P
0 votes
0 votes
if (a= something) means 'something' assigned to 'a' and it will return 'a' value (i.e. something) to if condition.

For i=0, if (a = cos pi*0/2) = if (a = 1) = if (a) = if (1)  i.e. true

For i=1, if (a = cos pi*1/2) = if (a = 0) = if (a) = if (0)   i.e false

For i=2, if (a = cos pi*2/2) = if (a = -1) = if (a) = if (-1) i.e. true

It will print 101.

Related questions

1 votes
1 votes
1 answer
1
Rohit Gupta 8 asked Nov 8, 2017
454 views
What does the following fragment of C- program print?char t[] = "PROGRAM1234"; char *r = t; printf ("%s", r + r[6]- r[3]);Explain.
1 votes
1 votes
2 answers
4
Khushal Kumar asked Jul 7, 2017
604 views
#include <stdio.h int x = 20; int f1() { x = x+10; return x;} int f2() { x = x-5; return x;} int main() { int p = f1() + f2(); printf ("p = %d", p); return 0; }