Int is an integer definition, and A and B cannot be decimals.
%d is also used to display integers.
Yours should be:
Floating a=20.526, b = 20.533
printf("%6.2f%.2f\n ",a,b);
%.2 means to keep 2 decimal places.
Attached:
Full format of printf format control:
%-0 m.n l or h format characters
The following is a description of the items that make up the format description:
①%: the opening symbol of format description, which is essential.
②-:Yes-indicates left-aligned output; If omitted, it means right-aligned output.
③0: 0 means that the specified space is filled with 0, and if omitted, it means that the specified space is not filled.
④ m.n: m refers to the domain width, that is, the number of characters occupied by the corresponding output item on the output device. N refers to accuracy. The number of decimal places used to describe the output real number. When n is specified for, the implied precision is n=6 bits.
⑤l or h:l means long type of integer and double type of real type. H is used to change the format character of an integer to a short integer.
-
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 a =- 1;
printf("%d,%o ",a,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 the" 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.