Because the data you output is less than 3 bits, there is a space in front of the output, and there is no space in front of more than 3 bits, so output together.
When "%3d" is changed to "%4d", it means that the output integer data takes up 4 bits. If it is less than 4 bits, a space is added before the output. Your data has only 3 digits, so there is a space in front of it.
However, these four digits will be output together. The solution is to output with the format character "%d" without specifying the width of integer data, and let it be output according to the actual length, followed by 1 spaces.
These two output methods specify the integer data width and do not specify the integer data width. If the columns are aligned, the integer data width is specified. If the columns are separated by spaces, the second method is used.