Program to check logical operations_1
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 \n",num); } else if(choice==2) { printf("to clear a particular bit\n"); num=num&~(1<<bit); printf("number is %d \n",num); //return; } else if(choice==3) { printf("to complement a particular bit\n"); num=num^(1<<bit); printf("number is %d \n",num); } else if(choice==4) { printf("to test a particular bit\n"); num&(1<<bit)?printf("set \n"):printf("clear \n"); } else if(choice==5) { printf("exit\n"); } else { printf("eneter currect choice\n"); } //printf("number is %d",num); }OutPut:
madan@madan-Lenovo-G570:~/madan$ cc ex43.c madan@madan-Lenovo-G570:~/madan$ ./a.out enter a num and bit 34 4 enter any choice 1 to set a particulart bit number is 50