C program to find maximum between three numbers using conditional operator

Write a C program to enter three numbers from user and find maximum between three numbers using conditional/ternary operator ?:.

Example

Input

Input num1: 10
Input num2: 20
Input num3: 30

Output

Maximum is 30

Required knowledge

Basic C programming, Conditional operator

Check this program using if else

Read more - Program to find maximum between three numbers using if else

Program to find maximum between three numbers

/**
 * C program to find maximum between three numbers using conditional operator
 */

#include <stdio.h>

int main()
{
    int num1, num2, num3, max;

    /*
     * Input three numbers from user
     */
    printf("Enter three numbers: ");
    scanf("%d%d%d", &num1, &num2, &num3);

    /* Finds maximum between three */
    max = (num1>num2 && num1>num3) ? num1 :
          (num2>num3) ? num2 : num3;

    printf("\nMaximum between %d, %d and %d = %d", num1, num2, num3, max);

    return 0;
}

Output

Enter three numbers: 10
20
30

Maximum between 10, 20 and 30 = 30

Happy coding 😉

Write your doubts or suggestion. I will try my best to help. You must escape source code before commenting. To format your source code paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>