adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C and C++ to print truth table using logical operators

Program in C and C++ to print truth table using logical operators
C Program
#include<stdio.h>
 int main()
  {
    int a,b,i;
    printf("\t\tTruth Table\n\n");
    printf(" A\tB\tA.B\tA+B\t!A\t!B\n");
    for(i = 0;i <= 3;i++)
    {
        a = i / 2;
        b = i % 2;
        printf(" %d\t%d\t%d\t%d\t%d\t%d\n",a,b,a&&b,a||b,!a,!b);
    }
    return 0;
  }
C++ Program
#include<iostream>
 using namespace std;
 int main()
  {
    int a,b,i;
    cout<<"\t\tTruth Table\n\n";
    cout<<" A\tB\tA.B\tA+B\t!A\t!B\n";
    for(i = 0;i <= 3;i++)
    {
        a = i / 2;
        b = i % 2;
        cout<<" "<<a<<"\t"<<b<<"\t"<<(a&&b)<<"\t"<<(a||b)<<"\t"<<!a<<"\t"<<!b<<endl;
    }
    return 0;
  }
Output :-




Post a Comment

1 Comments

Anonymous said…
what if I need 3 condition?