Skip to content

Instantly share code, notes, and snippets.

@suryansh011
Created November 9, 2021 09:08
Show Gist options
  • Save suryansh011/91dbfbaa3f5b14d0ab302435b9e94e48 to your computer and use it in GitHub Desktop.
Save suryansh011/91dbfbaa3f5b14d0ab302435b9e94e48 to your computer and use it in GitHub Desktop.
Conjunction, Disjunction, Negation & Implication
#include<stdio.h>
char print(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",print(i),print(j),print(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",print(i),print(j),print(b[i][j]));
}
}
printf("\nThe Truth Table for Negation: \n");
printf(" A : C\n");
for(i=0;i<=1;i++)
{
printf(" %c : %c\n",print(i),print(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",print(i),print(j),print(d[i][j]));
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment