//%4d用来表示数字的宽度为4.
#include
int main()
{
printf("%4d\n", 3);
printf("%4d\n", 33);
printf("%4d\n", 333);
return 0;
}
用 % 04d 来控制显示宽度,表示当位数不足 4 位时,前面填 0 显示/#include
//int main()
{
printf("%04d\n", 3);
printf("%04d\n", 33);
printf("%04d\n", 333);
return 0;
}
//可以使用 printf 操作来输出小数,使用的格式符为%lf (lf 代表 long float-point)。
#include
int main()
{
printf("x=%lf", 12.34);
return 0;
}
//我们可以控制小数点后的位数显示。例如, % .2lf,表示在显示输出的时候,小数点后面
//只保留 2 位,后面的值四舍五入。
#include
int main()
{
double a = 12.34;
printf("a=%.3lf\n", a);
return 0;
}