Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Roll No.

: 2100320120147 Name: Sahil Salim

Practical No. – 8

Objective: : Write a program in c to find the truth table of different gates

Theory: OR Gate: The function of a logical OR gate efficiently finds the maximum between two
binary digits,
Y=A+B

AND Gate: AND gate is a digital device which produces high output only when all inputs are
high and produces low output at all other inputs conditions.
Y=A.B

NOT Gate: A logic gate which performs the function of logical operator NOT is called as NOT
gate. Some of the function of NOT gate are as follow: It performs a basic logic function
called inversion or complementation.
Y=A’

NAND Gate: It is a combination of an AND gate and NOT gate. If we connect the output of
AND gate to the input of a NOT gate, the gate so obtained is known as NAND gate.
Y= (A.B)’

Source Code: #include<stdio.h>


void main()
{
int a[]={0,0,1,1};
int b[]={0,1,0,1};
int c;
printf("\nEnter 1 for Not Gate");
printf("\nEnter 2 for And Gate");
printf("\nEnter 3 for OR Gate");
printf("\nEnter 4 for Nand Gate");
printf("\nEnter 5 for Nor Gate");
printf("\nEnter 6 for XOR Gate");
printf("\nEnter 7 for And XNOR");
printf("\nEnter your choice");
scanf("%d",&c);
switch(c)
{
case 1:
printf("\na anot ");
for (int x=0;x<4;x++)
{
if(a[x]==1)
printf("\n%d 0",a[x]);
else
printf("\n%d 1",a[x]);
}

break;
case 2:
printf("\na b output");
for(int x=0;x<4;x++)
{
int r=a[x]*b[x];
printf("\n%d %d %d",a[x],b[x],r);
}
break;
case 3:
printf("\na b output");
for(int x=0;x<4;x++)
{
if(a[x]==1 || b[x]==1)
printf("\n%d %d 1",a[x],b[x]);
else
printf("\n%d %d 0",a[x],b[x]);
}
break;
case 4:
printf("\na b output");
for(int x=0;x<4;x++)
{
int r=a[x]*b[x];
if(r==1)
printf("\n%d %d 0",a[x],b[x]);
else
printf("\n%d %d 1",a[x],b[x]);
}
break;
case 5:
printf("\na b output");
for(int x=0;x<4;x++)
{
if(a[x]==1 || b[x]==1)
printf("\n%d %d 0",a[x],b[x]);
else
printf("\n%d %d 1",a[x],b[x]);
}
break;
case 6:
printf("\na b output");
for(int x=0;x<4;x++)
{
if(a[x]==1 && b[x]==1)
printf("\n%d %d 0",a[x],b[x]);
else if(a[x]==0 && b[x]==0)
printf("\n%d %d 0",a[x],b[x]);
else
printf("\n%d %d 1",a[x],b[x]);
}
break;
case 7:
printf("\na b output");
for(int x=0;x<4;x++)
{
if(a[x]==1 && b[x]==1)
printf("\n%d %d 1",a[x],b[x]);
else if(a[x]==0 && b[x]==0)
printf("\n%d %d 1",a[x],b[x]);
else
printf("\n%d %d 0",a[x],b[x]);
}
break;
default:
printf("\nInvalid Choice");
}
}

Output:

You might also like