Jump to content

To find minimum of three numbers using ternary (conditional) operator

From IdeaWazaWiki
Revision as of 06:50, 17 May 2007 by wikademia>MichaelFrey

<source lang="c">/* To find the minimum of three numbers using the conditional operator */

  1. 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>