Presentation is loading. Please wait.

Presentation is loading. Please wait.

DeMorgan's & related Laws

Similar presentations


Presentation on theme: "DeMorgan's & related Laws"— Presentation transcript:

1 DeMorgan's & related Laws

2 Given a Conditional Expression,
When its NOT true Given a Conditional Expression, apply the NOT operator !(cond)

3 How are these laws useful?
if (cond) // do this when cond is true else // do this when !cond is true

4 if (cond) { } else // !cond
Useful else comment if (cond) { } else // !cond

5 Useful else comment if (a < 0) cout << "negative"; else // a >= 0 cout << "zero or positive";

6 < >= > <= == !=
Relational Operators Operator "Not of" the Operator < >= > <= == !=

7 || && ! Logical Operators Operator "Not of" the Operator
! ! cond is cond

8 if ((a <= 3) ||(b != 0)) { } else { // ((a > 3) && (b == 0))
Example 1 if ((a <= 3) ||(b != 0)) { } else { // ((a > 3) && (b == 0))

9 if ((a > 3) &&(b == 0)) { } else { // ((a <= 3) || (b != 0))
Example 2 if ((a > 3) &&(b == 0)) { } else { // ((a <= 3) || (b != 0))

10 Example 3 if ((a >=0) && (a<=9)) cout << "single digit number"; else // (a < 0) || (a > 9) cout << "notsingle digit num";

11 if (!(a > 3)) { } else { // (a > 3) is !!(a>3)
Example 4 if (!(a > 3)) { } else { // (a > 3) is !!(a>3)


Download ppt "DeMorgan's & related Laws"

Similar presentations


Ads by Google