C语言笔记2

IO1.0

#include <stdio.h>

/* 将输入复制到输出;版本1 */
main()
{
    int c;

	c = getchar();
	while(c != EOF){
		putchar(c);
		c = getchar();
	}
}

 

IO2.0

#include <stdio.h>

/* 将输入复制到输出;版本2 */
main()
{
    int c;

	while((c = getchar()) != EOF){
		putchar(c);
	}
}

 

nc1.0

#include <stdio.h>

/* 统计输入的字符数;版本1 */
main()
{
    long nc;

	nc = 0;
	while(getchar() != EOF)
		++nc;
	printf("%ld\n", nc);
}
 

nc2.0

#include <stdio.h>

/* 统计输入的字符数;版本2 */
main()
{
    double nc;

	for(nc = 0; getchar() != EOF; ++nc)
		;	/* 空语句 */
	printf("%.0f\n", nc);
}
 

nl1.0

#include <stdio.h>

/* 统计输入的行数;版本1 */
main()
{
    int c, nl;

	while((c = getchar()) != EOF)
		if(c == '/n')
			++nl;
	printf("%d\n", nl);
}
 

nbntnl1.0

#include <stdio.h>

/* 统计输入的空格、制表符、换行符个数;版本1 */
main()
{
	int c, nb, nt, nl;

	nb = 0;
	nt = 0;
	nl = 0;

	while((c = getchar()) != EOF){
		if(c == ' '){
			++nb;
		}
		if(c == '\t'){
			++nt;
		}
		if(c == '\n'){
			++nl;
		}
	}
	printf("%d %d %d", nb, nt, nl);
}

 

nbntnl2.0

#include <stdio.h>

/* 统计输入的空格、制表符、换行符个数;版本2 */
main()
{
	int c, nb, nt, nl;

	nb = 0;
	nt = 0;
	nl = 0;

	while((c = getchar()) != EOF){
		if(c == ' '){
			++nb;
		}
		else if(c == '\t'){
			++nt;
		}
		else if(c == '\n'){
			++nl;
		}
	}
	printf("%d %d %d", nb, nt, nl);
}
 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值