Skip to main content

//Relational(Comparison) Operator

 //Relational(Comparison) Operator


  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int a = 21;
  6. int b = 10;//int use for integer value.

  7. //equal to
  8.     if( a == b) // (a=21 == b=10) is False; Therefore a is not equal to b.
  9.                //the two given values are equal to each other then result will be True, Otherwise it returns False.
  10. {
  11. cout <<"a is equal to b" << endl; //"cout" use for print line.
  12. }

  13. else
  14. {
  15. cout <<"a is not equal to b" << endl; //"endl" use for linebreak.
  16. }

  17. //not equal to
  18.     if( a != b) // (a=21 != b=10) is True; Therefore a is not equal to b.
  19.                // '!'not is True statement consider False and False statement consider to True.
  20.     {
  21.     cout <<"a is not equal to b" << endl; 
  22.     }

  23.     else
  24.     {
  25.     cout <<"a is equal to b" << endl;
  26.     }

  27. //less than
  28.     if( a < b) //(a=21 < b=10) is False; Therefore a is not less than b.
  29.               //the first value is less than the second value then result will be True, Otherwise it returns False.
  30.         { 
  31.         cout <<"a is less than b" << endl;
  32.         }

  33.         else 
  34.         {
  35.         cout <<"a is not less than b" << endl;
  36.         }

  37. //grater than
  38.     if( a > b)//(a=21 > b=10) is True; Therefore a is grater than b.
  39.               //the first value is grater than the second value then result will be True, Otherwise it returns False.
  40.         { 
  41.         cout <<"a is grater than b" << endl;
  42.         }

  43.         else 
  44.         {
  45.         cout <<"a is not grater than b" << endl;
  46.         }

  47. //less than or equal to
  48.     if( a <= b) //(a=21 <= b=10) is False; Therefore a is not less than or equal to  b.
  49.               //the first value is less than or equal to  the second value then result will be True, Otherwise it returns False.
  50.         { 
  51.         cout <<"a is less than or equal to b" << endl;
  52.         }

  53.         else 
  54.         {
  55.         cout <<"a is not less than or equal to b" << endl;
  56.         }

  57. //grater than or equal to
  58.     if( a >= b) //(a=21 >= b=10) is True; Therefore a is grater than or equal to b.
  59.                //the first value is grater than or equal to the second value then result will be True, Otherwise it returns False.
  60.         { 
  61.         cout <<"a is grater than or equal to b" << endl;
  62.         }

  63.         else 
  64.         {
  65.         cout <<"a is not grater than or equal to b" << endl;
  66.         }

  67. return 0;
  68. }


//Execute


//Output

/*

//equal to

a is not equal to b


//not equal to

a is not equal to b


//less than

a is not less than b


//grater than

a is grater than b


//less than or equal to

a is not less than or equal to b


//grater than or equal to

a is grater than or equal to b

*/



                                             //ThE ProFessoR