forked from Sourabh1Bhardwaj/Data-structure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNandgate.c
55 lines (41 loc) · 951 Bytes
/
Nandgate.c
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
a = 1
b = 2
even_sum = 2
c = a + b
while c<4000000:
a = b
b = c
if c % 2 == 0:
even_sum += c
c = a + b
c = a + b
print('even sum : ', even_sum)
https://www.geeksforgeeks.org/program-to-implement-logic-gates/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[5] = { 1, 0, 1, 0};
int b[5] = { 0, 1, 1, 0};
int i, x,y,z;
// xor
for (i = 0; i < 4; i++) {
x = a[i] ^ b[i];
printf("\n %d XOR %d = %d\n",
a[i], b[i],x); }
// nand
for (i = 0; i < 4; i++) {
if (a[i] == 1 && b[i] == 1)
y = 0;
else
y = 1;
printf("\n %d NAND %d = %d\n",
a[i], b[i], y);
}
// nor
for (i = 0; i < 4; i++) {
z = !(a[i] + b[i]);
printf("\n %d NOR %d = %d",
a[i], b[i], z);
}
}