10. reset the rightmost set bit

 

N = 7

7  =     0 1 1 1

6  = & 0 1 1 0

     =    0 1 1 0  ( = 6)

 

N = 6

6   =    0 1 1 0

5   = &0 1 0 1

     =    0 1 0 0  ( = 4)

 

 

           Code :

cin>>n;

x = n&(n-1);

cout<<x<<endl;

 

Comments