You are on page 1of 2

Discrete structures and Logic Lab(KCS-353)

EXPERIMENT No. - 6

AIM: To print Truth table of logic gates AND,OR,NOT.

DESCRIPTION: Basic gates AND,OR,NOT accepts input and gives a particular output.AND gives
true when both input are true , OR gives true when either of the input is true, NOT gate inverses the
input i.e, true gives false and false gives true.

CODE:

#include <stdio.h>
int ttand(int a,int b)
{
if(a==1&&b==1)
return 1;
else
return 0;
}
int ttor(int a,int b)
{
if(a==1||b==1)
return 1;
else
return 0;
}
int ttnot(int a)
{
if(a==0)
return 1;
else
return 0;
}
int main()
{ int ch,res,A,B;
printf("\n1. print the truth table of AND");
printf("\n2. print the truth table of OR");
printf("\n3. print the truth table of NOT");
printf("\nEnter the choice");
scanf("%d",&ch);
switch(ch)
{
case 1:
for(A=0;A<=1;A++){
for(B=0;B<=1;B++){
res=ttand(A,B);
printf("%d\t%d\t%d\n",A,B,res);
}
}

DIVAKAR 2100910130045 IT1 A(2)


Discrete structures and Logic Lab(KCS-353)

break;
case 2:
for(A=0;A<=1;A++){
for(B=0;B<=1;B++){
res=ttor(A,B);
printf("%d\t%d\t%d\n",A,B,res);
}
}
break;
case 3:
for(A=0;A<=1;A++){
res=ttnot(A);
printf("%d\t%d\n",A,res);
}
break;
case 4:
break;
}
return 0;
}

OUTPUT:

1. print the truth table of AND


2. print the truth table of OR
3. print the truth table of NOT
Enter the choice 1
0 0 0
0 1 0
1 0 0
1 1 1

1. print the truth table of AND


2. print the truth table of OR
3. print the truth table of NOT
Enter the choice 3
0 1
1 0

DIVAKAR 2100910130045 IT1 A(2)

You might also like