14/11/2015

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

Problem :- 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 see this C++ Program For Draw A Perfect Christmas Tree

Solution :-

#include<iostream>

using namespace std;
int main()
{
int a,b,c;
//By-Ghanendra badav
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:-

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

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

1 comment:

  1. write a code for the input expression by the user.

    ReplyDelete