Write an algorithm to determine maximum and minimum of three numbers using ternary operator.

#include 

int main()

{

 int a, b, c, max,min;

 printf("Enter three numbers: ");

 scanf("%d%d%d", &a, &b, &c);

 max = (a > b && a > c) ? a :

 (b > c) ? b : c;

 min = (a < b && a < c) ? a :

 (b < c) ? b : c;

printf("\nMaximum between %d, %d and %d = %d", a, b, c, max);

printf("\nMaximum between %d, %d and %d = %d", a, b, c, min);

return 0;

}
Next Post Previous Post
No Comment
Add Comment
comment url