![]() |
VOOZH | about |
The task is to write a program to find the largest number using ternary operator among:
Examples:
Input : 10, 20 Output : Largest number between two numbers (10, 20) is: 20 Input : 25 75 55 15 Output : Largest number among four numbers (25, 75, 55, 15) is: 75
A Ternary Operator has the following form,
exp1 ? exp2 : exp3
The expression exp1 will be evaluated always. Execution of exp2 and exp3 depends on the outcome of exp1. If the outcome of exp1 is non zero then exp2 will be evaluated, otherwise, exp3 will be evaluated.
Largest number between 5 and 10 is 10.
Largest number among 5, 10 and 15 is 15.
Largest number among 5, 10, 15 and 20 is 20.
For all the above programs :
Time Complexity: O(1)
Auxiliary Space: O(1)