德摩根定律和C ++ [英] DeMorgan's law and C++
本文介绍了德摩根定律和C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于以下每个示例,请编写等效的C ++表达式,而无需任何一元否定运算符(!).(!=仍然允许)
For each of the following write the equivalent C++ expressions, without any unary negation operators (!). (!= is still permitted)
使用迪摩根定律
-
!(P&& Q)=!P ||!Q
-
!(P || Q)=!P&&!Q
对于
-
!(x!= 5&& x!= 7)
-
!(x< 5 || x> = 7)
-
!(!(a> 3&& b> 4)&&(c!= 5))
我的答案:
-
(x> 5 || x< 5)||(x> 7 || x< 7)
-
x> = 5&&x <7
-
(a> 3&& b> 4)&&(c!= 5)
这些对吗?如果没有,您能给我答案并解释为什么错了吗?
Are these correct? If not, can you give me answers and explain why they are wrong?
我是C ++的初学者,请放轻松.
I am a beginner in C++ so take it easy.
推荐答案
检查一下:
!(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
因此,您的解决方案中只有#2是正确的.
So, just #2 from your solutions is correct.
这篇关于德摩根定律和C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文