DeMorgan's law and C++

天涯浪子 提交于 2019-12-01 10:55:25

问题


For each of the following write the equivalent C++ expressions, without any unary negation operators (!). (!= is still permitted)

Use DeMorgan's law

  • !( P && Q) = !P || !Q
  • !( P || Q) = !P && !Q

For

  1. !(x!=5 && x!=7)
  2. !(x<5 || x>=7)
  3. !( !(a>3 && b>4) && (c != 5))

My answers:

  1. (x>5 || x<5) || (x>7 || x<7)
  2. x>=5 && x < 7
  3. (a>3 && b > 4) && (c!=5)

Are these correct? If not, can you give me answers and explain why they are wrong?

I am a beginner in C++ so take it easy.


回答1:


Check this out:

!(x!=5 && x!=7)                 -->    x==5 || x==7

!(x<5 || x>=7)                  -->    x>=5 && x<7

!( !(a>3 && b>4) && (c != 5))   -->    (a>3 && b>4) || c==5

So, just #2 from your solutions is correct.



来源:https://stackoverflow.com/questions/18949375/demorgans-law-and-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!