In: Computer Science
#include <iostream>
using namespace std;
int disjunction(bool a, bool b)
{
//This function returns the value of a∨b
if(a==true||b==true)
return 1;
else
return 0;
}
int negation(bool a)
{
//This function returns the value of ~a
if(a==true)
return 0;
else
return 1;
}
int main() {
// declare the bool
bool a = true;
bool b= true;
//Print the disjunction function
printf("Disjunction Truth Table");
printf("\n\nA\tB\tO/P");
printf("\n%d\t%d\t%d",a,b,disjunction(a,b));
printf("\n%d\t%d\t%d",a,!b,disjunction(a,!b));
printf("\n%d\t%d\t%d",!a,b,disjunction(!a,b));
printf("\n%d\t%d\t%d",!a,!b,disjunction(!a,!b));
//Print the negation function
printf("\n\nNegation Truth Table");
printf("\n\nA\t~A");
printf("\n%d\t%d",a,negation(a));
printf("\n%d\t%d",!a,negation(!a));
//Printing the P ∨ ~P equation
printf("\n\nTruth Table for P ∨ ~P");
printf("\n\nP\t~P\tP∨~P");
printf("\n%d\t%d\t%d",a,negation(a),disjunction(a,negation(a)));
printf("\n%d\t%d\t%d",!a,negation(!a),disjunction(a,negation(!a)));
return 0;
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Snapshot of Output: