Find the Greatest Number Using Ternary Operator ( ?: ) in C


This program is a simple example of using the ternary operator in C. The ternary operator is a shorthand way of writing an if-else statement. It takes the form of "condition ? true_statement : false_statement". In this program, the ternary operator is used to compare the values of two variables, 'a' and 'b', and determine which one is greater.

The program starts by prompting the user to enter two integers, 'a' and 'b'. The values are then stored in the variables using the scanf() function. Next, the ternary operator is used to compare the values of 'a' and 'b'. If the value of 'a' is greater than 'b', the operator will execute the statement "printf("First value is Biggest:%d",a)" and print out the message "First value is Biggest" followed by the value of 'a'. If the value of 'b' is greater, the operator will execute the statement "printf("Second value is Biggest:%d",b)" and print out the message "Second value is Biggest" followed by the value of 'b'.

Source Code

#include<stdio.h>
int main()
{
 int a,b;
 printf("\nEnter the First value:");
 scanf("%d",&a);
 printf("\nEnter the Second value:");
 scanf("%d",&b);
 a>b?printf("First value is Biggest:%d",a):printf("Second value is Biggest:%d",b);
 return 0;
}
To download raw file Click Here

Output

Enter the First value : 5
Enter the Second value :7
Second value is Biggest :7

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C