统计各类字符个数

相关知识(略)
编程要求
根据提示,在右侧编辑器Begin-End处补充代码,输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。

输入
一行字符。
输出
统计每种字符的个数值。

#include 

int main(void)
{
    char b;
    int letters=0, space=0, digit=0, other=0;

    while((b=getchar())!='\n')
    if(b>='A'&&b<='Z')
        {
            letters++;
        }
        else if (b>='a'&&b<='z')
        {
            letters++;
        }
        else if (b>='0'&&b<='9')
        {
            digit++;
        }
        else if (b==' ')
        {
            space++;
        }
        else
        {
            other++;
        }

        printf("%d %d %d %d", letters, digit, space, other);
        return 0;
        
}

你可能感兴趣的:(c语言)