C++ Program for Logical and Conditional Operators

Master C++ with Real-time Projects and Kickstart Your Career Start Now!!

Program 1

// Demo of Logical and Conditional operator
#include<iostream>
#define clrscr() system("cls")
using namespace std;
int main()
{
    int a,b,c;
    clrscr();
    // cout<<"Enter two no";
    //  cin>>a>>b;
     c=! 50;
     cout<<c;

    //   a=90;
    //   b=5;
    // c=(++a>50) || (++b<8);  //Short Circuit
    // cout<<a<<"  "<<b<<"  "<<c;
    
    return 0;
}

Program 2

// Demo for conditional operator ? :
#include<iostream>
#define clrscr() system("cls")
using namespace std;
int main()
{
    //int a,b,c;
    int n;
    clrscr();
//     cout<<"Enter a number";
//     cin>>n;
//    n%2?cout<<"No is odd":cout<<"No is even";
 'A' ?cout<<"Hello":cout<<"Bye";
       
    // cout<<"Enter two Number";
    // cin>>a>>b;
    //0?cout<<"Hello":cout<<"Bye";
    return 0;
}

Program 3

// Program for  Grater 4 Number:
#include<iostream>

using namespace std;
int main()
{
    char ch;
    cout<<"Enter a character";
    cin>>ch;
    system("cls");
ch=='a' ||ch=='e'|| ch=='i'||ch=='o' ||ch=='u' || ch=='A' ||ch=='E'|| ch=='I'||ch=='O' ||ch=='U'? cout<<"Vowel":cout<<"Consonent";
//    int a,b,c,d,x,y,z;
//    system("cls");
//    cout<<"Enter Four Number";
//    cin>>a>>b>>c>>d;
//    x=a>b?a:b;
//    y=c>d?c:d;
//    z=x>y?x:y;
//    cout<<"Grater No is :"<<z;
}

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *