C Program Find Largest of Three Using Ternary Operator

By | March 7, 2020

Find Largest of Three Using Ternary Operator: C Program

Find Largest of Three

#include <stdio.h> 
  
int main() 
{ 
     
    int n1, n2, n3, max; 
      
     
    printf("Enter first number=");
	scanf("%d",&n1);
	
	
	printf("Enter second number=");
	scanf("%d",&n2);
	
	printf("Enter third number=");
	scanf("%d",&n3);
	
	max = (n1 > n2) ? (n1 > n3 ? n1 : n3) : (n2 > n3 ? n2 : n3); 
      
     
    printf("Largest number among %d, %d and %d is %d.",n1, n2, n3, max); 
  
    return 0; 
} 

Output

Enter first number=10
Enter second number=4
Enter third number=80
Largest number among 10, 4 and 80 is 80.

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *