统计大写字母、小写字母、数字、空格以及其他字符个数

#include<stdio.h>
int main()
{
    int i,j,a=0,b=0,c=0,d=0,oth=0;
    char s[3][80];
    for(i=0;i<3;i++)
    {
        gets(s[i]);
        for(j=0;j<80&&s[i][j]!='\0';j++)
        {
            if(s[i][j]>='A'&&s[i][j]<='Z')
                a++;
            else if(s[i][j]>='0'&&s[i][j]<='9')
                b++;
            else if(s[i][j]>='a'&&s[i][j]<='z')
                c++;
            else if(s[i][j]==' ')
                d++;
            else
                oth++;
        }
    }
    printf("大写字母个数:%d\n小写字母:%d\n数字:%d\n空格:%d\n其他字符:%d",a,c,b,d,oth);
    return 0;
}

发布了89 篇原创文章 · 获赞 24 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/zhangxue1232/article/details/104830462
今日推荐