5.4输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数

//C程序设计第四版(谭浩强)
//章节:第五章 循环结构程序设计 
//题号:5.4
//题目:输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
#include <stdio.h>
int main()
{
	char c;
	int letter=0,space=0,number=0,other=0;
	printf("请输入一行字符:");
	while((c=getchar())!='\n')
	{
		if(c>='a'&&c<='z'||c>='A'&&c<='Z')
			letter++;
		else if(c==' ')
			space++;
		else if(c>='0'&&c<='9')
			number++;
		else
			other++;
	}
	printf("letter:%d\nspace:%d\nnumber:%d\nother:%d\n",letter,space,number,other);
	return 0;
	
 } 

猜你喜欢

转载自blog.csdn.net/weixin_44589540/article/details/86578389