Skip to main content

//Logical Operator

 //Logical Operator


  1. #include <iostream>
  2. using namespace std;

  3. int main()
  4. {
  5. int a = 50;
  6. int b = 30; //int use for integer value.

  7. //Logical AND
  8. //we use also  Logical NOT
  9. if (!((a > b) && (a != b))) // !(a=50 > b=30) is False && (a=50 != b=30) is True; Therefore this statement is False.
  10.                            // when both statement are True then result will be True.
  11. {
  12. cout<<"First statement is true"<<endl; //"cout" use for print line. 
  13. }
  14. else //when if condition false then else condition executed
  15. {
  16. cout<<"First statement is false"<<endl; //"endl" use for linebreak.
  17. }

  18. // Logical OR
  19. if ((a < b) || (a != b)) // (a=50 < b=30) is False || (a=50 != b=30) is True; therefore this statement is True.
  20.                         //if one(or both) statement is True then result will be True, Otherwise it returns False.
  21.                        // '!'not is True statement consider False and False statement consider to True.
  22. {
  23. cout<<" Second statement is true"<<endl;
  24. }
  25. else
  26. {
  27. cout<<"Second statement is false"<<endl;
  28. }

  29. return 0;
  30. }

//Execute


//Output

/*

//Logical AND

First statement is false


//Logical OR

Second statement is true

*/





                                                    //ThE ProFessoR