DeMorgan's law and C++

10,398

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.

Share:
10,398
jshm415
Author by

jshm415

Updated on June 17, 2022

Comments

  • jshm415
    jshm415 almost 2 years

    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.