fork download
  1. #include <stdio.h>
  2.  
  3. int main ( )
  4.  
  5. {
  6.  
  7. int ivalue = 7; /* simple integer variable */
  8.  
  9. float fvalue = 10.235; /* simple floating point variable */
  10.  
  11. printf ("%i \n", ivalue); /* no special format */
  12.  
  13. printf ("%3i \n", ivalue); /* width of 3 minimum spaces */
  14.  
  15. printf ("%03i \n", ivalue); /* width of 3 spaces padded with zeros, not spaces) */
  16.  
  17. printf ("%f \n", fvalue); /* Yikes! No width, but lots of zeros will be printed after the decimal point */
  18.  
  19. printf ("%9.3f \n", fvalue); /* width of 7 spaces, with only two digits printed pass the decimal */
  20.  
  21. printf ("%-9.3f \n", fvalue); /* left justify the number , use a minus sign before the width */
  22.  
  23. return (0);
  24.  
  25. }
  26.  
  27.  
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
7 
  7 
007 
10.235000 
   10.235 
10.235