Skip to content

Instantly share code, notes, and snippets.

@suryansh011
Created November 9, 2021 09:21
Show Gist options
  • Save suryansh011/67fc1e7d64b48867b3b165250120585e to your computer and use it in GitHub Desktop.
Save suryansh011/67fc1e7d64b48867b3b165250120585e to your computer and use it in GitHub Desktop.
Program 6 (CDNI Truth Table)
#include<stdio.h>
char TorF(int i) {
if (i == 1)
return 'T';
else
return 'F';
}
int main() {
int a[2][2], b[2][2], c[2], d[2][2];
int i, j;
for(i = 0; i <= 1; i++) {
for(j = 0; j <= 1; j++) {
a[i][j] = ( i&&j );
b[i][j] = (i || j);
d[i][j] = (!i || j);
}
}
for(i=0;i<=1;i++) {
c[i] = ( !i );
}
printf("\nThe Truth Table for Conjunction: \n");
printf(" A B : C\n");
for(i=0; i<=1; i++) {
for(j=0; j<=1; j++) {
printf(" %c %c : %c\n", TorF(i), TorF(j), TorF(a[i][j]));
}
}
printf("\nThe Truth Table for Disjunction: \n");
printf(" A B : C\n");
for(i = 0; i <= 1; i++) {
for(j = 0; j <= 1; j++) {
printf(" %c %c : %c\n", TorF(i), TorF(j), TorF(b[i][j]));
}
}
printf("\nThe Truth Table for Negation: \n");
printf(" A : C\n");
for(i = 0; i <= 1; i++) {
printf(" %c : %c\n", TorF(i), TorF(c[i]));
}
printf("\nThe Truth Table for Implication: \n");
printf(" A B : C\n");
for(i = 0; i <= 1; i++) {
for(j = 0;j <= 1; j++) {
printf(" %c %c : %c\n", TorF(i), TorF(j), TorF(d[i][j]));
}
}
printf("\nNAME\nROLL\nSECTION");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment