User Tools

Site Tools


cs:c_language:printf_format
Site was transfered to www.skenz.it
Please, always refer to this link with the following URL: https://www.skenz.it/cs/c_language/printf_format

Printf format

Concepts:
Use of the function printf to format the output

Text:
Given a float variable:

float x = 12.12;

Produce the following output:

12.120000
12.120000
 12.120000
12.12
     12.12
0000012.12

Solution:

printf_format.c
/* Example of Use of the function printf to format the output */
 
#include <stdio.h>
 
 
int main(){
  float x = 12.12;
 
  printf("%f\n", x);
  printf("%4f\n", x);
  printf("%10f\n", x);
  printf("%.2f\n", x);
  printf("%10.2f\n", x);
  printf("%010.2f\n", x);
 
  return 0;
}

If you found any error, or if you want to partecipate to the editing of this wiki, please contact: wiki [at] altervista.org

You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/cs/c_language/printf_format
/membri/wiki/data/pages/cs/c_language/printf_format.txt · Last modified: 2015/10/28 15:22 (external edit)


Policy sui Cookie