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
#include <stdio.h>
#include <stdlib.h>
bool cool(bool a, bool b, bool c) {
return (a && b) || (b && c);
}
int main() {
//Print out simple truth table
printf(" a b c | S\n-------+---\n");
unsigned int i = 0, j;
bool bits[3];
for (; i < 8; i++) {
//Calculate the bits
for (j = 0; j < 3; j++)
bits[j] = (i >> j) & 1;
//Print row
printf(
" %d %d %d | %d\n",
bits[2],
bits[1],
bits[0],
cool(bits[0], bits[1], bits[2])
);
}
}