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