字符统计

# include<stdio.h>
char c[3][81];
int upp,low,sp,num,oth;
int main()
{
    upp=low=sp=num=oth=0;
    printf("请输入:\n");
    for(int i=0;i<3;i++)
        gets(c[i]);
    printf("\n");
    for(i=0;i<3;i++)
        printf("%s\n",c[i]);

    for(i=0;i<3;i++)
    {
        for(int j=0;j<80;j++)
        {
                if(c[i][j]=='\0') break;
                if(c[i][j]==' ') sp++;
                else if(c[i][j]>='A'&&c[i][j]<='Z') upp++;
                else if(c[i][j]>='a'&&c[i][j]<='z') low++;
                else if(c[i][j]>='0'&&c[i][j]<='9') num++;
                else oth++;
        }
    }
    printf("\n大写:%d\n小写:%d\n空格:%d\n数字:%d\n其他:%d\n",upp,low,sp,num,oth);
    return 0;
}

运行结果如下:

 

posted @ 2020-03-06 18:25  kakusan  阅读(182)  评论(0编辑  收藏  举报