Monday, 8 December 2014

Program to check logical operations_2
#include<stdio.h>
main()
{
int choice,num,bit;
printf("enter a num and bit\n");
scanf("%d%d",&num,&bit);
printf("enter any choice\n");
scanf("%d",&choice);
if(choice==1)
{
printf("to set a particulart bit\n");
num=num|(1<<bit);
printf("number is %d",num);
}
if(choice==2)
{
printf("to clear a particular bit\n");
num=num&~(1<<bit);
printf("number is %d",num);
//break;
}
if(choice==3)
{
printf("to complement a particular bit\n");
num=num^(1<<bit);
printf("number is %d",num);
//break;
}
if(choice==4)
{
printf("to test a particular bit\n");
num&(1<<bit)?printf("set"):printf("clear");
//break;
}
if(choice==5)
{
printf("exit");
//break;
}
if(choice>5)
{
printf("eneter currect choice\n");
}
//printf("number is %d",num);
}
OutPut:
madan@madan-Lenovo-G570:~/madan$ cc ex44.c
madan@madan-Lenovo-G570:~/madan$ ./a.out
enter a num and bit
23
4
enter any choice
2
to clear a particular bit
number is 7