#include<stdio.h>
main()
{
int Fahrenheit;
for (Fahrenheit = 0; Fahrenheit <= 300; Fahrenheit = Fahrenheit + 20)
printf("%3d %06.3f\n", Fahrenheit, (5.0/9.0)*(Fahrenheit-32));
}
上述源的输出:
0 -17.778
20 -6.667
40 04.444
60 15.556
80 26.667
100 37.778
120 48.889
140 60.000
160 71.111
180 82.222
200 93.333
220 104.444
240 115.556
260 126.667
280 137.778
300 148.889
请解释一下上面程序中‘printf’函数中‘06.3f’的作用。
最佳答案
0
左边补0
6
字符串长度应至少为 6 个字符
.3
精度为小数点后3位
f
它接受一个float
(或double
)变量
关于c - 在 C 程序中使用 '%06.3f',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29606309/