RicardasSim

De Morgan's Laws

Apr 4th, 2019
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int main (int argc, char **argv){
  6.  
  7. /*
  8. De Morgan's Laws
  9. not (A or B) = not A and not B
  10. not (A and B) = not A or not B
  11. */
  12.    
  13. printf("not (A or B) = not A and not B\n");
  14. printf("not (A and B) = not A or not B\n");
  15.  
  16. printf("!(0||0): %s\t", !(0||0) ? "true" : "false");
  17. printf("!0&&!0: %s\n", !0&&!0 ? "true" : "false");
  18.  
  19. printf("!(0||1): %s\t", !(0||1) ? "true" : "false");
  20. printf("!0&&!1: %s\n", !0&&!1 ? "true" : "false");
  21.  
  22. printf("!(1||0): %s\t", !(1||0) ? "true" : "false");
  23. printf("!1&&!0: %s\n", !1&&!0 ? "true" : "false");
  24.  
  25. printf("!(1||1): %s\t", !(1||1) ? "true" : "false");
  26. printf("!1&&!1: %s\n", !1&&!1 ? "true" : "false");
  27.  
  28. printf("!(0&&0): %s\t", !(0&&0) ? "true" : "false");
  29. printf("!0||!0: %s\n", !0||!0 ? "true" : "false");
  30.  
  31. printf("!(0&&1): %s\t", !(0&&1) ? "true" : "false");
  32. printf("!0||!1: %s\n", !0||!1 ? "true" : "false");
  33.  
  34. printf("!(1&&0): %s\t", !(1&&0) ? "true" : "false");
  35. printf("!1||!0: %s\n", !1||!0 ? "true" : "false");
  36.  
  37. printf("!(1&&1): %s\t", !(1&&1) ? "true" : "false");
  38. printf("!1||!1: %s\n", !1||!1 ? "true" : "false");
  39.  
  40. return 0;
  41. }
  42.  
  43. /*
  44. output:
  45.  
  46. not (A or B) = not A and not B
  47. not (A and B) = not A or not B
  48. !(0||0): true   !0&&!0: true
  49. !(0||1): false  !0&&!1: false
  50. !(1||0): false  !1&&!0: false
  51. !(1||1): false  !1&&!1: false
  52. !(0&&0): true   !0||!0: true
  53. !(0&&1): true   !0||!1: true
  54. !(1&&0): true   !1||!0: true
  55. !(1&&1): false  !1||!1: false
  56.  
  57. */
Advertisement
Add Comment
Please, Sign In to add comment