C Program to Find Maximum of Two Numbers using Conditional Operator

  • Write a C program to find maximum of the two numbers using conditional or ternary operator.
  • How to find largest of the two numbers using conditional statement.

Required Knowledge

In this program, we will use conditional operator to find maximum of two numbers.

C program to find maximum of two numbers using conditional operator

C program to find maximum of two numbers using conditional operator

#include <stdio.h>  
   
int main() {  
    int a, b, maximum;  
   
    /* Take two numbers as input from user
  using scanf function */
    printf("Enter Two Integers\n");  
    scanf("%d %d", &a, &b);  
   
    if(a == b){
        printf("Both Equal\n");
        return 0;
    }
    /* Finds maximum using Ternary Operator */ 
    maximum = (a > b) ? a : b;  
   
    printf("%d is Maximum\n", maximum);  
   
    return 0;  
}