C program to find the Largest of Three Numbers using Conditional Operator.


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);



Sample Output: ( using GNU GCC Compiler with Code Blocks IDE )

Enter Three Numbers: 5 7 6
The Largest Number is: 7

Leave a Reply

Your email address will not be published.