1.
printf("%03d\n", x);
%03d中的3表示最少输出三位数字,0表示如果数字不足3位,在最左边用0补足。
printf("%5d\n");
其中%5d表示按照5位数打印,不足5位在前面补空格。
2.
scanf()函数的返回值是读入的变量个数
常这样使用
while(scanf("%d", &x) == 1) {
//处理输入
}
或者
while(scanf("%d%d", &m, &n) == 2) {
//处理输入
}
3.
输出程序所用时间(s)
#include<stdio.h>
#include<time.h>
int main() {
printf("Time used = %.2f\n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
4.
调试的时候利用文件重定向的输入输出
工具-编译选项-编译时加入一下命令 -DLOCAL
将以下代码放入main函数
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
5.
精确到小数点后n位,其中星号表示不确定的位数
printf("%.*f\n", n,x); //n用来确定小数点后的位数
6.
数