输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数

#include<stdio.h>
int main()
{
    char c;
    int letters=0,spaces=0,digits=0,others=0;
    printf("请输入一串任意的字符:\n");
    while((c=getchar())!='\n')
    {
        if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
        letters++;
        else if(c>='0'&&c<='9')
        digits++;
        else if(c==' ')
        spaces++;
        else
        others++;
    }
    printf("字母有%d个,数字有%d个,空格有%d个,其他有%d个",letters,digits,spaces,others);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38452951/article/details/80716713