Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What is the difference between printf("%2d\n ",k) and printf("%6d\n", k) in the output results of various formats of computer C language?
What is the difference between printf("%2d\n ",k) and printf("%6d\n", k) in the output results of various formats of computer C language?
%d Integer data input/output format string, where d is preceded by a number, such as %2d, %6d, indicating the number of digits in the input/output number.

Specific:

%2d: Output data in 2-bit format. If there are less than 2 digits, fill them with spaces to make up 2 digits; If it exceeds 2 digits, all digits will be displayed. For example, if you want to output the number 2, the output result is "_2", "stands for space; If you want to output the number 1234, the input result is "1234".

%02d: If you understand the above format, you will understand it better. 0 means less than 2 digits, so it should be filled with 0, not the space above. For example, if you enter the number 1, the output will be "0 1". If it exceeds 2 digits, all digits will be displayed, and 0 will not be filled.