1--首先是printf里常用到的几种
1-1--
#include <stdio.h>
int main() {
int k=12;
printf("%9d,\n",k);
printf("%-9d,",k);
}
12,
12 ,
--------------------------------
Process exited after 0.06664 seconds with return value 0
请按任意键继续. . .
1-2--
#include <stdio.h>
int main() {
int k=12;
printf("%+9d,\n",k);
printf("%-+9d,",-k);
}
+12,
-12 ,
--------------------------------
Process exited after 0.07627 seconds with return value 0
请按任意键继续. . .
1-3--
#include <stdio.h>
int main() {
int k=12;
printf("%09d,\n",k);
printf("%-09d,",k);
}
000000012,
12 ,
--------------------------------
Process exited after 0.07621 seconds with return value 0
请按任意键继续. . .
1-4--
#include <stdio.h>
int main() {
double k=12;
printf("%9.2f,\n",k);
printf("%-9.2f,\n",k);
}
12.00,
12.00 ,
--------------------------------
Process exited after 0.07102 seconds with return value 0
请按任意键继续. . .
1-5--
#include <stdio.h>
int main() {
int k=12;
printf("%*f,\n",k,12.0);
printf("%.*f,\n",k,12.0);
}
12.000000,
12.000000000000,
--------------------------------
Process exited after 0.07147 seconds with return value 0
请按任意键继续. . .
2--接下来讲scanf里面的
2-1--
#include <stdio.h>
int main() {
int num;
scanf("%*d%d",&num);
printf("%d",num);
}
123 456
456
--------------------------------
Process exited after 3.478 seconds with return value 0
请按任意键继续. . .
2-2--
#include <stdio.h>
int main() {
int num;
int n=3;
while(n--)
{
scanf("%i",&num);
printf("%d\n",num);
}
}
123
123
0x12
18
012
10
--------------------------------
Process exited after 7.503 seconds with return value 0
请按任意键继续. . .
2-3--
#include <stdio.h>
int main() {
char a[20]={0};
scanf("%*[^,],%[^.]",a);
puts(a);
}
1234asd,liu.
liu
--------------------------------
Process exited after 11.17 seconds with return value 0
请按任意键继续. . .
3--注意printf还有一个\n。
#include <stdio.h>
int main() {
int num;
int k1=scanf("%i",&num);
int k2=printf("%i\n",num);
printf("%d:%d",k1,k2);
}
1234
1234
1:5
--------------------------------
Process exited after 0.9277 seconds with return value 0
请按任意键继续. . .