Write a C++ program to verify that the proposition P ∨¬(P ∧Q) is a tautology.
If you could include comments to explain the code that would be much appreciated! :)
Thank you so much!
#include <iostream>
using namespace std;
int main()
{
//boolean variable declaration
bool p,q;
//display table header
cout << "P Q P^Q ~P^Q (p v ~(P^Q)) \n";
//display the table data
for ( int i = 0 ; i < 4 ; i++ )
{
p = ( i >> 0 ) & 0x01;
q = ( i >> 1 ) & 0x01;
//display p and q
cout<<p<<" ";
cout<<q<<" ";
cout<<(p&&q)<<"
"<<!(p&&q)<<"
"<<(p||!(p&&q))<<endl;
}
return 0;
}
OUTPUT:
So, the given expression is a tautology because all output are 1 or true.
Get Answers For Free
Most questions answered within 1 hours.