代码演示为: 

//输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
#include <stdio.h>

int main()
{
	int numbers=0,words=0,others=0,space=0,n;
	printf("Please enter a paragraph:\n");
	while ((n = getchar())!= '\n')
	{
		if (n >= '0' && n <= '9')
		{
			numbers++;
		}
		else if (n == ' ')
		{
			space++;
		}
		else if (n >= 'a' && n <= 'z' || n >= 'A' && n <= 'Z')
		{
			words++;
		}
		else
		{
			others++;
		}
	}
	printf("numbers:%d\nspace:%d\nwords:%d\nothers:%d\n", numbers, space, words, others);
	return 0;
}

结果展示:

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐