文件(1)格式化输入输出

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
请按任意键继续. . .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值