/* * truthtable.c * Douglas L. Jones * University of Illinois at Urbana-Champaign * September 19, 2012 * * (c) 2012 by Douglas L. Jones * This work is made available according to the Creative Commons "Attribution" license * http://creativecommons.org/licenses/by/3.0/ * * truthtable.c: Computes and prints the truthtable for a 3-input logic function */ #include /* Define constants */ int main() { /*********************/ /* Declare variables */ /*********************/ int a,b,c; /* counters for the input logic values */ int result; /*************************************/ /* Compute and print the truth table */ /*************************************/ printf(" A B C | OUT \n"); /* print truth table header */ printf("----------|-----\n"); /* cycle through all input bit combinations */ for ( a = 0; a <= 1; a = a + 1 ) { for ( b = 0; b <= 1; b = b + 1 ) { for ( c = 0; c <= 1; c = c + 1 ) { result = a & b & c; /* compute desired logical operation */ printf(" %d %d %d | %d \n", a, b, c, result); } } } return 0; }