-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdstl5.c
More file actions
100 lines (88 loc) · 1.3 KB
/
dstl5.c
File metadata and controls
100 lines (88 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int OR(int,int);
int AND(int,int);
int XOR(int,int);
int NOT(int);
void main()
{
int a,b,ch,o;
printf("\n-:MENU:-\n1.AND\n2.OR\n3.NOT\n4.XOR\n0.Exit\n");
do{
printf("\nEnter Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf ("\nTruth Table for AND\nA B \tO");
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{ o=AND(a,b);
printf("\n%d %d \t%d",a,b,o);
}
}
break;
case 2:printf ("\nTruth Table for OR\nA B \tO");
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
o=OR(a,b);
printf("\n%d %d \t%d",a,b,o);
}
}
break;
case 3: printf ("\nTruth Table for NOT\nA \tO");
for(a=0;a<=1;a++)
{
o=NOT(a);
printf("\n%d \t%d",a,o);
}
break;
case 4:printf ("\nTruth Table for AND\nA B \tO");
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
o=XOR(a,b);
printf("\n%d %d \t%d",a,b,o);
}
}
break;
case 0:
break;
default: printf("\nError");
}
}while(ch!=0);
getch();
}
int OR(int a, int b)
{
if(a==0&&b==0)
return 0;
else
return 1;
}
int AND(int a, int b)
{
if (a==1&&b==1)
return 1;
else
return 0;
}
int NOT(int a)
{
if (a==0)
return 1;
else
return 0;
}
int XOR(int a,int b)
{
if (a==0&&b==1||a==1&&b==0)
return 1;
else
return 0;
}