C Online Compiler
Example: Greatest of Two Numbers in C using Ternary Operator
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Greatest of Two Numbers in C using Ternary Operator #include <stdio.h> // It's the main function of the program int main() { int number_1, number_2; // Step-1 Take two input values from the User printf("Enter First Number: "); scanf("%d", &number_1); printf("Enter Second Number: "); scanf("%d", &number_2); // Step-2 Check if the first number is the Greatest or second number is the Greatest or both numbers are equal number_1 > number_2 ? printf("\nGreatest Number :: %d\n", number_1) : ( number_1 < number_2 ? printf("\nGreatest Number :: %d\n", number_2) : printf("\nBoth are equal number\n") ); return 0; }
9 9
Output
Clear
ADVERTISEMENTS