C. Examples of formatting output code and examples of formatting code
Example of C formatted output code
/* C Format output:> understanding: Format control string: (Format control string), composed of Conversion specifier, Flag, and Filed Width ), precision, Literal character. 1. printing in different hexadecimal formats: % d, % o, % x; 2. print floating point: % e, usually six digits after the decimal point. % g: determines whether it is represented by floating point or scientific notation based on the absolute value of the data. 3. Print the domain width: 5 in % 5d indicates that the domain width is 5. If the field width is exceeded, the data representation is not affected. The field width is larger than the actual data number, and the data is automatically aligned to the right. 4. precision printing: %. in 5f, the precision of the floating point number is determined as 5 digits after the decimal point. in 5d, the precision indicates the minimum number of digits of the printed data. If the precision before 5 is a point (.) or zero (0) is filled with 0. If there is no embellishment before 5, then-> reference domain width %. the accuracy in 5 s indicates the maximum number of characters printed from a string. 5. MARK:-(minus sign) add + before positive in the left-aligned + (plus sign) field width, and add-Before negative. # Add the corresponding prefix to different hexadecimal values, for example: when 0, 0x, 0X, or floating point does not have a decimal part, the decimal point time is forcibly displayed: Dec 29,201 7 */# include
Int main () {int a = 789; float B = 12.345; const char * s = "heheda! "; Printf (" % 05d \ n ", a); printf (" % # 05o \ n ", a); printf (" % # 05x \ n ", ); printf ("%-5d \ n", a); printf ("% + 5d \ n", a); printf ("% 020f \ n", B ); printf ("% 10.2f \ n", B); printf ("% 010.2f \ n", B); printf ("% 10.2e \ n", B ); printf ("% 010.2e \ n", B); printf ("%-5f \ n", B); printf ("% + 5f \ n", B ); printf ("% 020s \ n", s); printf ("%. 5s \ n ", s); return 0;}/************** 00789014250x315789 + 7890000000000012.345000 12.350000012.35 1.23e + 001 01.23e + 00112.345000 + 12.345000000000000000 heheda! Hehed press any key to continue ...*/