write a computer program that produces the desired output from the given input. Input: Truth values for two statement letters A and BOutput: Corresponding truth values (appropriatelylabeled, of course) for A Λ B, A ∨ B, A → B, A ↔ B, A′
write a computer 
Input: Truth values for two statement letters A and B
Output: Corresponding truth values (appropriately
labeled, of course) for
                                          A Λ B, A ∨ B, A → B, A ↔ B, A′
Objective: This program prints the truth table of certain logic gates.
Programming language: since no language is mentioned, C++ is used.
Answer:
#include <iostream> 
#include <stdlib.h> 
using namespace std;
void printAND(int A[],int B[])
{
    int Z;
    printf("AND gate\n");
    printf("A |\t |B\tZ=A AND B");
    for(int i = 0; i <4;i++) { 
        //computing AND gate values
        Z = A[i] & B[i]; 
        printf("\n %d |\t %d|\t%d",A[i],B[i],Z); 
    } 
}
void printOR(int A[],int B[])
{
    int Z;
    printf("OR gate\n");
    printf("A |\t |B\t|Z=A OR B");
    for(int i = 0; i <4;i++) { 
        //computing AND gate values
        Z = A[i] | B[i]; 
        printf("\n %d |\t %d|\t%d",A[i],B[i],Z); 
    } 
}
void printNOT(int B[])
{
    int Z;
    printf("NOT gate\n");
    printf("B\t|Z=NOT B");
    for(int i = 0; i <2;i++) { 
        //computing NOT gate values
        Z = !B[i]; 
        printf("\n%d|\t%d",B[i],Z); 
    } 
}
void printIMPLY(int A[],int B[])
{
    int Z;
    printf("IMPLES THAT\n");
    printf("A |\t |B\t|Z=A -> B");
    for(int i = 0; i <4;i++) { 
        //computing IMPLIES THAT
        if(A[i]==1 && B[i]==0)
            Z = 0; 
        else
            Z = 1;
        printf("\n %d |\t %d|\t%d",A[i],B[i],Z); 
    } 
}
void printEQUI(int A[],int B[])
{
    int Z;
    printf("EQUIVALENCE\n");
    printf("A |\t |B\t|Z=A <-> B");
    for(int i = 0; i <4;i++) { 
        //computing IMPLIES THAT
        if(A[i]==B[i])
            Z = 1; 
        else
            Z = 0;
        printf("\n %d |\t %d|\t%d",A[i],B[i],Z); 
    } 
}
int main() 
{ 
    int A[5] = { 0, 0, 1, 1}; 
    int B[5] = { 0, 1, 0, 1}; 
    int Z; 
    printAND(A,B);
    cout<<"\n";
    printOR(A,B);
    cout<<"\n";
    printNOT(B);
    cout<<"\n";
    printIMPLY(A,B);
    cout<<"\n";
    printEQUI(A,B);
} 
Step by step
Solved in 3 steps with 1 images









