C program to compare 2 numbers using ternary operator


This content was proof-read by Grammarly. You can Try Grammary for FREE

Problem Statement

Write a program in C to compare 2 numbers without using if statement but instead use the ternary operator.

C program to compare 2 numbers using ternary operator

#include <stdio.h> 
int main() 
{ 
        int x=8, y=4 ; 
        y = ( x>y ? printf("x is greater") : printf("y is greater") ) ; 
}
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: