Professional Documents
Culture Documents
DMlab1 Merged
DMlab1 Merged
Submitted by Submitted to
Md. Tamim Iqbal Suhrid Shakhar Ghosh
Roll : 2103094 Assistant Professor
Section : B Department of CSE
Series : 21 RUET
Code:
#include<bits/stdc++.h>
using namespace std;
Analysis:
The provided C++ code generates a truth table for compound propositions
involving two Boolean variables, P and Q. It defines functions for negation,
conjunction, disjunction, implication, and biconditional operations. The main
function utilizes nested loops to systematically iterate through all possible
truth values for P and Q. The output is a well-formatted table presenting the
results of these logical operations.
This truth table serves as a valuable tool for examining the behavior of
compound propositions under diverse truth conditions. Through the concise
tabular format, the code effectively illustrates the logical relationships
between Boolean variables P and Q. In summary, the code provides a clear and
organized representation of the outcomes of different logical operations,
enhancing understanding of Boolean logic.
int main(){
bool ans=true;
cout<<"p\tQ\tR\tP->(Q^R)\t(P->Q)^R"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
for(int k=0;k<2;k++){
int a=imp(i,con(j,k));
int b=con(imp(i,j),k);
cout<<i<<"\t"<<j<<"\t"<<k<<"\t "<<a<<"\t\t
"<<b<<endl;
if(a!=b) ans=false;
}
}
}
if(ans) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
Output:
Analysis:
This C++ code generates a truth table for compound propositions
involving three Boolean variables P, Q, and R. It evaluates the
expressions P->(Q^R) and (P->Q)^R for all possible truth values of P,
Q, and R, and then checks if the two expressions always produce the
same result.