题目:编写程序分别统计一行字符中(不超过80个字符)英文大写字母,小写字母、数字,空格及其他字符的个数。
#include<stdio.h>
int main()
{
char ch;
int a = 0, b = 0, c = 0, d = 0;
printf("请输入一行字符\n");
while ((ch = getchar()) != '\n')
{
if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')
a = a + 1;
else if (ch >= '0' && ch <= '9')
b = b + 1;
else if (ch == ' ')
c = c + 1;
else
d = d + 1;
}
printf("字母数:%d\n数字字符数:%d\n空格数:%d\n其他字符数:%d\n", a, b, c, d);
return 0;
}