-->
Showing posts with label WAP to understand logical operator.. Show all posts
Showing posts with label WAP to understand logical operator.. Show all posts

Tuesday, April 14, 2020

WAP to understand logical operator.

//PROGRAM TO UNDERSTAND following logical operators
/*
and operator        &&
or operator         ||
not operator        !
*/
#include <iostream>//header file
#include<stdlib.h>//header file to handle system("cls")

using namespace std;//to handle all standard characters/functions,reserved words  used in program. we do not use in turboc++ compiler

int main()//main function
{
    int number1,number2;
    cout<<"enter two numbers"<<endl;//prints message to input numbers
    cin>>number1>>number2;          //gets inputs using chaining concept
    system("cls");                  //clears the screen
    cout<<"number1="<<number1<<endl<<"number2="<<number2<<endl;
    cout<<"result of (number1>=20 && number2<=50):-"<<(number1>=20 && number2<=50)<<endl;
    //returns 0 or 1(after testing both conditions) depending upon they are  false or true.Actually, it multiplies both results and returns 0/1.
    cout<<"result of (number1>=20 || number2<=50):-"<<(number1>=20 || number2<=50)<<endl;
    //returns 0 or 1(after testing both conditions) depending upon they are  false or true.
    //Actually, it adds both results and returns 0/1.
    cout<<"result of (!number1>20):-"<<!(number1>20)<<endl;
    //returns 0 or 1 if it is true or false.
    return 0;
}