C Program to Find Maximum of Three Numbers using Ternary Operator

In this C program, we will find maximum of three numbers using conditional operator.

Required Knowledge

Algorithm to find maximum of three numbers using conditional operator
Let A, B and C are three numbers.
  • We will first find the largest of A and B. Let it be X.
  • Then we will compare X with third number C to get the overall largest number.

C program to find maximum of three numbers using conditional operator

#include <stdio.h>  
  
int main()  {  
    int a, b, c, max;  
 
    printf("Enter Three Integers\n");  
    scanf("%d %d %d", &a, &b, &c);  
    
    max = (a > b)?((a > c)?a:c):((b > c)?b:c);
  
    /* Print Maximum Number */  
    printf("Maximum Number is = %d\n", max);  
  
    return 0;  
}
Output
Enter Three Integers
9 1 4
Maximum Number is = 9

Related Topics
C program to find maximum of three numbers
C program to find maximum of two numbers
C program to find maximum of two numbers using conditional operator
C program to print name of days in week using switch statement
C program to print even numbers between 1 to N using for and while loop
C program to print all factors of a number using for loop
C program to check a number is palindrome or not
C program to check armstrong number
C Program to find nPr and nCr
List of all C programs