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'.
#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
Enter the First value : 5 Enter the Second value :7 Second value is Biggest :7
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions