Greatest of three numbers using conditional (ternary) operator
C program to find the greatest of three numbers using Conditional (ternary) Operator.
Program
Output
Explanation
Three numbers are taken as input from the user in the variables named 'num1', 'num2' and 'num3' respectively.
First of all, condition
In Expression_2, condition
Similarly, in Expression_3, condition
First of all, condition
(num1 > num2)
is checked. If the condition results in true, then Expression_2 is executed and if the condition results in false, then Expression_3 is executed.
In Expression_2, condition
(num1 > num3)
is checked. If the condition results in true, then Expression_2_2 is executed and if the condition results in false, then Expression_2_3 is executed.
Similarly, in Expression_3, condition
(num2 > num3)
is checked. If the condition results in true, then Expression_3_2 is executed and if the condition results in false, then Expression_3_3 is executed.