What is ternary operator?
Syntax-
expression?value1:value2;
-Depend on the expression result that it is true or false it may return different results.
-it is conditional operator.
-If Expression is True then it will return value1.
-If Expression is False then it will return value2.
Find maximum of three number:
program:
#include< iostream>
using namespace std;
int main()
{
int a,b,c,max;
cout<<"Enter three numbersn";
cin>>a>>b>>c;
max=(a>b?a:b)>c?(a>b?a:b):c;
cout<<"Maximum is: "<< max;
return 0;
}
Enter three numbers
3 6 1
Maximum is: 6