C program to find maximum between two numbers using conditional operator

Write a C program to enter two numbers and find maximum between two numbers using conditional/ternary operator?:. How to find maximum or minimum between two numbers using conditional operator in C program.

Example

Input

Input first number: 10
Input second number: 20

Output

Maximum: 20

Required knowledge

Basic C programming, Conditional operator

Check this program using other approaches.

Read more -

Program to find maximum using conditional operator

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

#include <stdio.h>

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

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

    /* Find maximum using conditional operator */
    max = (num1 > num2) ? num1 : num2;

    printf("Maximum between %d and %d is %d", num1, num2, max);

    return 0;
}

Output

Enter two numbers: 10
20
Maximum between 10 and 20 is 20

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>