Enter the values of two numbers and find out largest number using conditional
operator(Ternary operator):
operator(Ternary operator):
#include<stdio.h> // Header File
#include<conio.h>
void main() // Main function of every C program
{
printf("Enter the values of a and b:"); // Output function display the message on screen
scanf("%d%d" ,&a,&b); // Input function used to enter or input values
c = a>b ? a : b; // Ternary operator
printf("Larger number=%d" ,c);
getch();
}
// End of main()
Output1:
Enter the values of a and b:
30
90
Largest number=90
// condition a>b is not TRUE so the value of "b" is executed.
Output2:
Enter the values of a and b:
60
20
Largest number=60
// condition a>b is TRUE so the value of "a" is executed.
0 Response to "C Program: Find out the Largest Number by using Ternary Operator:"
Post a Comment