C Primer Plus编程练习答案(Chapter8)

8.11.1

 

#include <stdio.h>
int main() {

	int ch;
	int num = 0;

	while ((ch = getchar()) != EOF) {
		num++;
		//putchar(ch);		   此两行为文件输出验证项
		//printf("%d \n", num);
	}

	printf("There are %d strings in the file.", num);

	return 0;
}

8.11.2

 

#include <stdio.h>
int main() {

	int ch;
	int n = 0;

	while ((ch = getchar()) != EOF) {
		if (ch == '\n') {
			printf("\\n");
		}
		else if (ch == ' ') {
			printf("\' \' -  0  ");
			n++;
		}
		else {
			putchar('\'');
			putchar(ch);
			putchar('\'');
			printf(" - %d  ", ch);
			n++;
		}
		if (n == 10 || ch == '\n') {
			printf("\n");
			n = 0;
		}
	}
	printf("^Z - %d  ", ch);

	return 0;
}

8.11.3

 

#include <stdio.h>
int main() {

	int ch;
	int num_Clt = 0, num_Slt = 0;

	while ((ch = getchar()) != EOF) {
		if (ch >= 65 && ch <=  90)
			num_Clt++;
		else if (ch >= 97 && ch <= 122)
			num_Slt++;
	}

	printf("There are %d Captial letters.", num_Clt);
	printf("There are %d Small letters.", num_Slt);

	return 0;
}
	

8.11.4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值