Truth Table for Two Variables

1.  Truth Table for Two Variables

#include <iostream.h>

 #include <conio.h>

 void main()

 {

 int p , q;

 clrscr();

 cout<<"Truth Table for Two Variables p and q\n\n";

 cout<<"p\tq\tAND\tOR\tNOT P\tXOR\tp->q\tp<->q\n";

 cout<<"-------------------------------------------------------------\n";

 for(p=0;p<=1;p++)

 {

 for(q=0;q<=1;q++)

    {

    //Display p and q

    cout<<p<<"\t"

      <<q<<"\t";

 

    //AND

    cout<<(p && q)<<"\t";

 

    //OR

    cout<<(p || q)<<"\t";

 

    //NOT P

    cout<<(!p)<<"\t";

 

    //XOR

    cout<<(p!=q)<<"\t";

 

    //Conditional p->q

    cout<<((!p)||q)<<"\t";

 

    //Biconditional p<->q

    cout<<(p==q)<<"\t\n";

 

    }

    }

    getch();

    }

 

 

 

 


Comments

Popular posts from this blog

Data Structure - Lab

Data Structure - Binary Tree

Mathematical Foundation - Unit 1