Write a menu driven program to perform following option Right shift Left shift One’s complement
#include<stdio.h>
#include<conio.h>
void main()
{
int no,ans,ch,b;
clrscr();
printf("\n enter the number = ");
scanf("%d",&no);
do
{
printf("\n 1:Right Shift ");
printf("\n 2:Left Shift ");
printf("\n 3:Ones compliment ");
printf("\n 4:Exit");
printf("\n ENTER YOUR CHOICE ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\n How Many Bits To Shift ");
scanf("%d",&b);
ans=no>>b;
printf("\n Answer is =%d",ans);
break;
case 2: printf("\n How Many Bits To Shift ");
scanf("%d",&b);
ans=no<<b;
printf("\n Answer is =%d",ans);
break;
case 3: printf("\n Ones Cmpliment");
ans=~no;
printf("\n ones compliment=%d",ans);
break;
case 4:printf("\n thank you \n");
getch();
exit(0);
default:printf("\n invalid choice \n");
getch();
}
}while(ch!=4);
}
#include<conio.h>
void main()
{
int no,ans,ch,b;
clrscr();
printf("\n enter the number = ");
scanf("%d",&no);
do
{
printf("\n 1:Right Shift ");
printf("\n 2:Left Shift ");
printf("\n 3:Ones compliment ");
printf("\n 4:Exit");
printf("\n ENTER YOUR CHOICE ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\n How Many Bits To Shift ");
scanf("%d",&b);
ans=no>>b;
printf("\n Answer is =%d",ans);
break;
case 2: printf("\n How Many Bits To Shift ");
scanf("%d",&b);
ans=no<<b;
printf("\n Answer is =%d",ans);
break;
case 3: printf("\n Ones Cmpliment");
ans=~no;
printf("\n ones compliment=%d",ans);
break;
case 4:printf("\n thank you \n");
getch();
exit(0);
default:printf("\n invalid choice \n");
getch();
}
}while(ch!=4);
}
thanx dude awsome work...
ReplyDelete