输入一行字符,分别统计出其英文字母,空格数字和其他字符的个数
#include<stdio.h>
int main()
{
char ch = 0;
char c = 0;
int a = 0, b = 0, e = 0, d = 0;
while ((c = getchar(ch)) != '\n')
{
if (c == ' ')
a++;
else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
b++;
else if (c >= '0' && c <= '9')
e++;
else
d++;
}
printf("空格=%d\n字母=%d\n数字=%d\n其他字符=%d\n", a, b,e, d);
return 0;
}
输出结果: