+ 2

How to Find greatest no where a=5; b=7;c=10 using ternery operators...

14th Jun 2017, 8:19 AM
Kishan Mittal
2 Answers
+ 5
int a=7; int b=10; int c=5; int x = 0; using if-else :- if(a>b) { if(a>c) x=a; else x=c; } else { if(b>c) x=b; else x=c; } using ternary :- x = (a>b)?(a>c)?a:c:(b>c)?b:c;
14th Jun 2017, 8:43 AM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 2
Use nested ternary operators. x = (a > b) ? ( (a > c) ? a : c ) : ( (b > c) ? b : c )
14th Jun 2017, 9:57 AM
Rohit Kanwar
Rohit Kanwar - avatar