Jump to content

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

From IdeaWazaWiki
Revision as of 20:53, 11 May 2009 by wikademia>Wikademia (4 revisions)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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