Answer:
int main()
{
int a,b,max,min;
cout<<"Enter 2 numbers\\";
cin>>a>>b; //asking numbers from user
max= a>b ? a : b; //using conditional operator to find larger
min= a>b ? b : a; //using conditional operator to find smaller
cout<<"\\Larger is "<<max;
cout<<"\\Smaller is "<<min;
return 0;
}
OUTPUT :
Enter 2 numbers
56
34
Larger is 56
Smaller is 34
Step-by-step explanation:
- In the above program, first user is asked to enter 2 numbers which needs to be compared.
- Conditional operator - This operator contains syntax - (condition ? true : false) . This is a ternary operator in which first operand checks the condition and if its true second operand is returned otherwise third is returned.
- Then conditional operator is used twice first to find larger number and then smaller.
- At last both numbers are printed.