al__nasim

left shift and right shift

Oct 30th, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int n,x,y,a,b;
  5.     while(1)//infinte loop
  6.     {
  7.         printf("Enter your Number: ");
  8.         scanf("%d",&n);
  9.         if(n == 0)break;//enter 0 to exit
  10.  
  11.         //left shift
  12.         printf("The number of bit you want to shift left: ");
  13.         scanf("%d",&a);
  14.         x=n << a;
  15.         printf("The result is: %d\n",y);
  16.  
  17.         //right shift
  18.         printf("The number of bit you want to shift right: ");
  19.         scanf("%d", &b);
  20.         y=n >> b;
  21.         printf("The result is: %d\n",y);
  22.     }
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment