Here in this program, we will write a code that will print the truth table for XY+Z.
Truth Table for XY+Z
C++:
#include<iostream.h> #include< conio.h> #include<stdio.h> #include<math.h> void main() { clrscr(); int a,b,c; cout<<"A\tB\tC\tAB+C"; for(a=0;a<=1;a++) for(b=0;b<=1;b++) for(c=0;c<=1;c++) { if(a*b+c==2) cout<<"\n\n"<<a<<"\t"<<b<<"\t"<<c<<"\t"<<"1"; else cout<<"\n\n"<<a<<"\t"<<b<<"\t"<<c<<"\t"<<a*b+c; } getch(); }
Output:
A B C AB+C 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
Python:
print("A\tB\tC\tAB+C") for a in range(0,2): for b in range(0,2): for c in range(0,2): if a*b+c==2: print("\n"+str(a)+"\t"+str(b)+"\t"+str(c)+"\t1") else: print("\n"+str(a)+"\t"+str(b)+"\t"+str(c)+"\t"+str(a*b+c))
Output:
A B C AB+C 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
People are also reading:
- WAP in C++ and python to check whether the number is even or odd
- Python Program to Add Two Matrices
- WAP to check whether a given character is an alphabet, digit or any special character
- Python Program to Find Sum of Natural Numbers Using Recursion
- Write a C++ Calculator to perform Arithmetic Operations using Switch Case
- Python Program to Multiply Two Matrices
- WAP in C to check whether the number is a Palindrome number or not
- Python Program to Shuffle a Deck of Cards
- WAP in C++ & Python for Armstrong Number
- Python Program to Swap Two Variables