Output long integer
G format symbols are used to output real numbers, and the output format is F format or E format. According to the size of data in width m, the system automatically selects the format with smaller width to output, and G format symbols do not output meaningless zeros after decimal point.

Example:

Master ()

{

float x = 654.32 1;

printf("%f,%e,%g ",x,x,x);

}

Print output: 654.320984, 6.54 10e+002, 654.438+0 (of which 654.984 output is caused by memory storage error).

Extended data

layout/format character

Format characters are used to specify the data type and output format of the output item.

①d format: used to output decimal integers. There are the following usages:

%d: Output according to the actual length of integer data.

% md: m is the width of the specified output field. If the number of digits of data is less than m, the left end is filled with spaces; If it is greater than m, it is output according to the actual number of digits.

%ld: output long integer data.

②o format: output integers in unsigned octal format. Long integers can be output in "%lo" format. You can also specify the width of the field output in "%mo" format.

Example:

Master ()

{? int? Answer? =? - 1;

printf("%d,%o ",? First,? a);

}

Operation results:-1, 177777

Program analysis:-1 (stored in the form of complement) in the memory unit is (111111/.

③x format: output integers in unsigned hexadecimal form. Long integers can be output in "%lx" format. You can also specify the field width and output it in "%mx" format.

④u format: output integers in unsigned decimal form. Long integers can be output in "%lu" format. You can also specify the field width to output in "%mu" format.

⑤c format: output a character.

⑥s format: used to output a string. There are several uses.

%s: For example, printf("%s ","China ") outputs" China "string (excluding double quotation marks).

%ms: The output string occupies m columns. If the length of the string itself is greater than m, it will break through the limit of obtaining m and output all strings. If the string length is less than m, the left blank is filled.

%-ms: If the length of the string is less than m, the string will be left and right filled with spaces within the range of m columns.

%m.ns: The output occupies m columns, but only the left n characters in the string are taken. These n characters are output on the right side of column M, with spaces on the left.

%-m.ns: where m and n have the same meaning, n characters are output on the left side of the range of m columns, and spaces are filled on the right side. If n>m is used, the value of n is automatically taken, which ensures the normal output of n characters.

⑦f format: used to output real numbers (including single precision and double precision) in decimal form. There are the following usages:

%f: No width is specified, all integer parts are output, and 6 decimal places are output.

%m.nf: the output * * * occupies m columns, including n decimal places, such as the left blank with a value width less than m.

%-m.nf: the output * * * occupies n columns, including n decimal places, for example, the width of the value is less than the right end of m to fill in spaces.

⑧e format: output real numbers in exponential form. The following forms can be used:

%e: The number part (also called mantissa) outputs 6 decimal places, and the exponent part occupies 5 or 4 digits.

The characters %m.ne and %-m.ne: m, n and "-"have the same meanings as before. Where n refers to the number of decimal places in the digital part of the data, and m refers to the width occupied by the whole output data.

⑨g format: automatically select the shorter output of F format or E format, and do not output meaningless zeros.

Reference link Baidu Encyclopedia? layout/format character