Installer et compiler ces fichiers dans votre répertoire de travail.

c02c.c
'
/* ------------------------------ */
/*  Save as :   c02c1.c           */
/* ------------------------------ */
#include    <stdio.h>
/* ------------------------------ */
#include      "z_s.h"
/* ------------------------------ */
int main(void)
{

 clrscrn();
 printf("                                    (%%12.2f)\n");
 printf("  Push the numbers on the right.          \n");
 printf("  And reserve a column of 12 characters \n\n");

 printf("  x = %12.2f %8.2f         \n",     1.,    1.);
 printf("  x = %12.2f %8.2f         \n",    12.,   12.);
 printf("  x = %12.2f %8.2f         \n",   123.,  123.);
 printf("  x = %12.2f %8.2f    \n\n\n\n",  1234., 1234.);

 printf("                                    (%%-12.2f)\n");
 printf("  Push the numbers on the left. (-)      \n");
 printf("  And reserve a column of 12 characters \n\n");
 
 printf("  x = %-12.2f %-8.2f       \n",    1.,    1.);
 printf("  x = %-12.2f %-8.2f       \n",   12.,   12.);
 printf("  x = %-12.2f %-8.2f       \n",  123.,  123.);
 printf("  x = %-12.2f %-8.2f       \n", 1234., 1234.);

 stop();

 return 0;
}


Sur la droite ou sur la gauche

  • %f  : pour afficher un double poussé sur la droite.
  • %-f  : pour afficher un double poussé sur la gauche.
  • %+-f  : pour afficher un double poussé sur la gauche avec un nombre signé.


Exemple de sortie écran :

                                     (%12.2f)
  Push the numbers on the right.         
  And reserve a column of 12 characters 

  x =         1.00     1.00         
  x =        12.00    12.00         
  x =       123.00   123.00         
  x =      1234.00  1234.00    



                                    (%-12.2f)
  Push the numbers on the left. (-)      
  And reserve a column of 12 characters 

  x = 1.00         1.00           
  x = 12.00        12.00          
  x = 123.00       123.00         
  x = 1234.00      1234.00        

 Press return to continue.
Cet article est issu de Wikibooks. Le texte est sous licence Creative Commons - Attribution - Partage dans les Mêmes. Des conditions supplémentaires peuvent s'appliquer aux fichiers multimédias.