Write a C++ & Python Program to print the truth table for XY+Z

Posted in

Vinay Khatri
Last updated on July 21, 2022

    Here in this program, we will write a code that will print the truth table for XY+Z.

    Truth Table for XY+Z

    C++ Program to print the truth table for XY+Z

    #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 Program to print the truth table for XY+Z

    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:

    Tags:
    truth table

    Leave a Comment on this Post

    0 Comments