C Program to find maximum number between three number using Conditional Operator

C Program to Find Maximum of Three Numbers using Conditional Operator
·                     Write a C program to find maximum of three numbers using conditional operator.
·                     How to find largest of three numbers using ternary operator.


Required Knowledge
·                     C printf and scanf functions
·                     Conditional Operator in C
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h> 
   
int main()  { 
    int a, b, c, max; 
    /*
     * Take three numbers as input from user
     */ 
    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


Comments

Most Viewed

Write C program to enter any year and check whether year is leap year or not using conditional/ternary operator.

WAP to input week number and print week day name.

C Program to Find Third Angle of a Triangle