// write a program in c to display the truth table for boolean opration. // SAAR #include #include // logic for OR gate int find_OR(int x,int y) { if(x==1 && y==1) return 1; if(x==1 && y==0 || x==0 && y==1) return 1; if(x==0 && y==0) return 0; } // logic for find AND int find_AND(int x,int y) { if(x==1 && y==1) return 1; else return 0; } // logic for find NOT int find_NOT(int x) { if(x==1) return 0; else return 1; } // Driver function int main() { int ch,a,b; printf("You have to choose one option from all of them :-\n"); printf("1. OR\n"); printf("2. AND\n"); printf("3. NOT\n"); printf("4 .exit\n"); while(1) { printf("\nEnter your choice\n"); scanf("%d",&ch); switch(ch) { case 1: printf("Give two input 1 for true and 0 for false\n"); scanf("%d%d",&a,&b); printf("Your resultant output is %d",find_OR(a,b)); break; case 2: printf("Give two input 1 for true and 0 for false\n"); scanf("%d%d",&a,&b); printf("Your resultant output is %d",find_AND(a,b)); break; case 3: printf("Give an input 1 for true and 0 for false\n"); scanf("%d",&a); printf("Your resultant output is %d",find_NOT(a)); break; case 4: exit( 0); default: printf("You have entered Wrong key, Please try again\n"); } } }
You have to choose one option from all of them :- 1. OR 2. AND 3. NOT 4 .exit Enter your choice 1 Give two input 1 for true and 0 for false 1 1 Your resultant output is 1 Enter your choice 1 Give two input 1 for true and 0 for false 0 1 Your resultant output is 1 Enter your choice 2 Give two input 1 for true and 0 for false 1 0 Your resultant output is 0 Enter your choice 2 Give two input 1 for true and 0 for false 0 0 Your resultant output is 0 Enter your choice 2 Give two input 1 for true and 0 for false 1 1 Your resultant output is 1 Enter your choice 3 Give an input 1 for true and 0 for false 1 Your resultant output is 0 Enter your choice 3 Give an input 1 for true and 0 for false 0 Your resultant output is 1 Enter your choice 4
0 Comments