有一篇文章,共3行文字,每行有10个字符。要求分别统计出其中英文大写字母、空格、英文小写字母、数字以及其他字符的个数
供参考:
#include<stdio.h>
int main()
{
char ch;
int lower = 0, upper = 0, dight = 0, blank = 0, other = 0;
while ((ch = getchar()) != EOF)
{
if (ch >= 'a' && ch <= 'z')
lower++;
else if (ch >= 'A' && ch <= 'Z')
upper++;
else if (ch >= '0' && ch <= '9')
dight++;
else if (ch == ' ')
blank++;
else
other++;
}
printf("upper = %d,blank = %d,lower = %d,digit = %d,other = %d",
upper, blank, lower, dight, other);
return 0;
}