Skip to content

Instantly share code, notes, and snippets.

@dchapman1988
Last active December 15, 2015 14:29
Show Gist options
  • Save dchapman1988/5275086 to your computer and use it in GitHub Desktop.
Save dchapman1988/5275086 to your computer and use it in GitHub Desktop.
DeMorgan's Theorem example in C

DeMorgan's Theorems state

!(A || B) == (!A && !B)
!(A && B) == (!A || !B)

Where A and B represent either a 0 or 1.

Assume the function f() is defined as

int f()
{
  return(1 && (30 % 10 >= 0) && (30 % 10 <= 3));
}

Applying DeMorgan's Theorem to the function f() means all these conditional statements will return true or 1 in the C programming language.

!f()  == !(1 && (30 % 10 >= 0) && (30 % 10 <= 3))   
!!f() == (!1 && !(30 % 10 >= 0) && !(30 % 10 <= 3)) 
f()   == 0 || (30 % 10 < 0) || (30 % 10 > 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment