More C Problems

C Questions Page 1(New)

C Questions Page 2

C Questions Page 3

C Questions Page 4

try to get solution

1. if( n%2 == 1)
          n+=x;
  else
          n+=y;

  can you do this in just one statement without using any conditional statement (if,turnery,switch) and % operator.

2.  implement rotate instruction of 8086 in just one statement.
    e.g.  1000 1000 =>  0001 0001 


3. for(i=0;i<50;i++)                  for(i=50;i>0;i--)
  {                                  {
    //some code here                      //code
  }                                  }

  which for statement is more efficient.


4.
  #define swap(a,b) t=a;a=b;b=t;

  static int a=5,b=6,t;

  void main()
  {
    if(a>b)
      swap(a,b);
    printf("a=%d \t b=%d",a,b);
  }

  options:
  1. a=5 b=6          2. a=6  b=5        3. a=6  b=0  4. not in above