In: Computer Science
write a program that will print a truth table for p ^ ~q.
Using C++ please.
//include headers
#include <iostream>
#include <iomanip>
using namespace std;
//driver function
int main()
{
//printing heading
cout<<"Truth table\n\n";
//printing the table headings i.e, column names
cout<<"p"<<setw(5)<<"q"<<setw(5)<<"~q"<<setw(8)<<"p^~q"<<endl;
//for each possible pair (p,q) where p,q belongs to [0,1]
for(int i=0;i<=1;i++){
for(int j=0;j<=1;j++){
//print the row
cout<<i<<setw(5)<<j<<setw(5)<<(!j)<<setw(6)<<(i^(!j))<<endl;
}
}
return 0;
}
Truth table
p q ~q p^~q
0 0 1 1
0 1 0 0
1 0 1 0
1 1 0 1
CODE
OUTPUT
So if you still have any doubt regarding this solution please feel free to ask it in the comment section below and if it is helpful then please upvote this solution, THANK YOU.