05-Logic operators- c++


Logic operators in c++

The basic logic operators are :-"and,or,not" operators.

&& - and operator

||    - or operator
!     - not operator



Program 1:- To find greatest among three numbers




#include<iostream>

using namespace std;


int main ()


{

    int a,b,c;
    cout<<"enter any three numbers a,b,c"<<endl;
    cin>>a>>b>>c;

          if(a>=b&&a>=c)


          {cout<<"a is greatest number"; }



           if(b>=a&&b>=c)


           {cout<<"b is greatest number"; }



            if(c<<a&&c>=b)


           {cout<<"c is greatest number"; }


    return 0;


}



Program 2:- 
The candidate is selected if his age is >= 18 years and height is >=172cm respectively.


#include<iostream>

using namespace std;


int main ()



{

    float age,height;

    cout<<"enter age and height"<<endl;


    cin>>age>>height;



    if(age>=18 && height>=172)


    {cout<<"congrats!! candidate selected";}



    else

    {cout<<"sory.. candidate not selected";}

    return 0;



}




















No comments:

Post a Comment