C++ Program to Print Truth Table of XY+Z

Here you will get 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

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

1 1 1 1

1 thought on “C++ Program to Print Truth Table of XY+Z”

Leave a Comment

Your email address will not be published. Required fields are marked *