C program to find the Largest of Three Numbers using Conditional Operator
C program to find the Largest of Three Numbers using Conditional Operator.
PROGRAM:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<stdio.h> int main() { int a,b,c,large; printf("\n Enter Three Numbers:"); scanf("%d %d %d", &a , &b , &c); large = (a > b && a > c ? a : b > c ? b:c) ; //if a>b and a>c then large=a, else check whether b>c if //yes large=b else large=c printf("\n The Largest Number is: %d",large); return(0); } |
Sample Output: ( using GNU GCC Compiler with Code Blocks IDE )
Enter Three Numbers: 5 7 6
The Largest Number is: 7
The Largest Number is: 7