C++ Program to Print Truth Table of XY+Z:Three loop initialize with zero and limit is 1 ,and use a formula to print a*b+c==2
C++ Program to Print Truth Table of XY+Z
#include<iostream>
using namespace std;
int main()
{
int x,y,z;
cout<<"X\tY\tZ\tXY+Z";
for(x=0;x<=1;++x)
for(y=0;y<=1;++y)
for(z=0;z<=1;++z)
{
if(x*y+z==2)
cout<<"\n\n"<<x<<"\t"<<y<<"\t"<<z<<"\t1";
else
cout<<"\n\n"<<x<<"\t"<<y<<"\t"<<z<<"\t"<<x*y+z;
}
return 0;
}
Output of Program
X Y Z XY+Z
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1