To find minimum of three numbers using ternary (conditional) operator
Appearance
<source lang="c">/* To find the minimum of three numbers using the conditional operator */
- include <stdio.h>
int main(void) {
int a, b, c, temp, min;
printf ("Enter three nos. separated by spaces: ");
scanf ("%d%d%d", &a, &b, &c);
temp = (a < b) ? a : b; min = (c < temp) ? c : temp;
printf ("The Minimum of the three is: %d", min);
/* indicate success */ return 0;
} /* Output:
Enter three nos. separated by spaces: 2 5 9 The Minimum of the three is: 2
- /
</source>