VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-find-the-largest-number-using-ternary-operator/

⇱ Program to Find the Largest Number using Ternary Operator - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to Find the Largest Number using Ternary Operator

Last Updated : 11 Jul, 2025

The task is to write a program to find the largest number using ternary operator among: 

  • Two Numbers
  • Three Numbers
  • Four Numbers

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.


Output: 
Largest number between 5 and 10 is 10.

 

Output: 
Largest number among 5, 10 and 15 is 15.

 

Output: 
Largest number among 5, 10, 15 and 20 is 20.

 

For all the above programs :

Time Complexity: O(1)

Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: