Advertisement
Tahamina_Taha

All logical operators

Feb 5th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. // All logical operators which commonly used in decision making
  4. int main()
  5. {
  6.   /*logical operator returns either 0 or 1
  7. depending upon whether
  8. expression results true or false.*/
  9.     int a,b,c,result;
  10.     printf(" Enter value of a b c: \n");
  11.     scanf("%d %d %d",&a,&b,&c);
  12.  
  13.     result = (a == b) && (c > b);//Logical AND. True only if all operands are true
  14.     printf("(a == b) && (c > b) is %d \n", result);
  15.     result = (a == b) && (c < b);
  16.     printf("(a == b) && (c < b) is %d \n", result);
  17.  
  18.     result = (a == b) || (c < b);//Logical OR. True only if either one operand is true
  19.     printf("(a == b) || (c < b) is %d \n", result);
  20.     result = (a != b) || (c < b);
  21.     printf("(a != b) || (c < b) is %d \n", result);
  22.  
  23.     result = !(a != b);//Logical NOT. True only if the operand is 0
  24.     printf("!(a == b) is %d \n", result); /* !(a != b) evaluates to 1 because operand (a != b) is 0 (false).
  25.      Hence, !(a != b) is 1 (true).*/
  26.     result = !(a == b);
  27.     printf("!(a == b) is %d \n", result); /* !(a == b) evaluates to 0 because (a == b) is 1 (true).
  28.      Hence, !(a == b) is 0 (false). */
  29.  
  30.  
  31.      return 0;
  32.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement