Q:

C++ Program Generate Truth Table Of X Y+C Using Loops

belongs to collection: Loop Programs In C ++Programming

0

Write A C++ Program Generate Truth Table Of  X Y+C Using Loops

Logic :-

 We need three loop initialize with zero and limit is 1 ,and use a formula to print a*b+c==2 .if you are facing problem to getting three loops

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>

using namespace std;
int main()
{
 int a,b,c;
 
 cout<<"Truth Table Of  AB+C\t";
 for(a=0;a<=1;++a)
 {
  for(b=0;b<=1;++b)
  {
   for(c=0;c<=1;++c)
   {
    if(a*b+c==2)
     cout<<"\n"<<a<<"\t"<<b<<"\t"<<c<<"\t1";
    else
     cout<<"\n"<<a<<"\t"<<b<<"\t"<<c<<"\t"<<a*b+c<<endl;
   }
  }
 }
  cout<<"\n\n";
return 0;
}

 

Output:

Truth Table Of  AB+C

0 0 0 0

0 0 1 1

0 1 0 0

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 1

1 1 1 1

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Program Convert Decimal Number To Binary Numbe... >>
<< C++ Program To Print A Reverse Number Using Loop...