home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / dos / prg / alb_c10 / chap_03 / ch03_04.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-08  |  1.1 KB  |  37 lines

  1. /*********************************************************************
  2. *  CH03_04.C                          L'opΘrateur ternaire     *
  3. *********************************************************************/
  4.  
  5. #include<stdio.h>     
  6.  
  7. main( void)
  8. {
  9.     float a= -5.43, b= 3.21, test0, test1, test2, Min, Max;
  10.  
  11.     test0= ( a> 0) ? ( a): ( -a);
  12.     /* renvoie la valeur absolue.                               */
  13.     printf(" test0= %f", test0);
  14.  
  15.     test1= ( a> b) ? ( a- b): ( b- a);
  16.     /* renvoie la valeur absolue de la diffΘrence.              */
  17.     printf("\n test1= %f", test1);
  18.  
  19.     test2= ( test0> b) ? ( test0- b): ( b- test0);
  20.     /* a est remplacΘ par sa valeur absolue avant le test.      */
  21.     printf("\n test2= %f", test2);
  22.  
  23.     Min= ( a< b) ? a: b;
  24.     /* renvoie la valeur du plus petit.                         */
  25.     printf("\n Min= %f", Min);
  26.  
  27.     Max= ( a> b) ? a: b;
  28.     /* renvoie la valeur du plus grand.                         */
  29.     printf("\n Max= %f", Max);
  30. }
  31.  
  32. /*
  33.  test0= 5.430000
  34.  test1= 8.639999    au lieu de 8.64 c'est une erreur d'arrondi!
  35.  test2= 2.220000
  36.  Min= -5.430000
  37.  Max= 3.210000                                */