C PROGRAM CODE
#include<stdio.h>
#include<string.h>
main()
{
int a,b,c;
char choice[2];
printf("\n Enter your Choice\n & for AND\n | for OR\n ^ for XOR\n ~ for Compliment\n << for Left Shift\n >> for Right Shift\n ");
scanf("%s",choice);
printf("\n Enter the value of a and b:\n ");
scanf("%d%d",&a,&b);
if(strcmp(choice,"&")==0)
{
c=a&b;
printf("\n %d & %d=%d\n",a,b,c);
}
else if(strcmp(choice,"|")==0)
{
c=a|b;
printf("\n %d | %d=%d\n",a,b,c);
}
else if(strcmp(choice,"^")==0)
{
c=a^b;
printf("\n %d ^ %d=%d\n",a,b,c);
}
else if(strcmp(choice,"~")==0)
{
printf("\n ~ %d=%d\n",a,~a);
printf("\n ~ %d=%d\n",b,~b);
}
else if(strcmp(choice,"<<")==0)
{
c=a<<b;
printf("\n %d << %d=%d\n",a,b,c);
}
else if(strcmp(choice,">>")==0)
{
c=a>>b;
printf("\n %d >> %d=%d\n",a,b,c);
}
else
{
printf("\n Invalid Choice\n" );
}
}
No comments:
Post a Comment