1.代码
1 void main() 2 { 3 float a=3.1415926; 4 int b=2; 5 printf("float=%f ",a); 6 printf("float=%.5f ",a); 7 printf("float=%.4f ",a); 8 printf("float=%2f ",a); 9 printf("float=%5.2f ",a);//总宽度是5,2位是小数 10 printf("float=%3.6f ",a);//小数点后6位,超过3,则保持原数据不变 11 printf("b=%2d ",b); 12 printf("b=%7d ",b); 13 printf("b=%.5d ",b); 14 system("pause"); 15 }
2. 运行结果