统计各类字符个数

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

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

#include <stdio.h>

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;
        
}

猜你喜欢

转载自blog.csdn.net/weixin_51676760/article/details/110350284