字符串和格式化输入输出(查漏补缺详细版)---永远不要认为你很牛,随便一个知识点就可以难倒你(三)

2014-11-24 08:13:42 · 作者: · 浏览: 2
unsigned width, precision;
int number = 256;
double weight = 242.5;
printf("What field width \n");
scanf("%d", &width); www.2cto.com
printf("The number is :%*d:\n", width, number);
printf("Now enter a width and a precision:\n");
scanf("%d %d", &width, &precision);
printf("Weight = %*.*f\n", width, precision, weight);
printf("Done!\n");
return 0;
}
输出结果:
What field width
6
The number is : 256:
Now enter a width and a precision:
8 3
Weight = 242.500
Done!
Press any key to continue
代码很简单,估计一看都明白了,我就不多说了。