C语言:任意输入10个字符,统计英文字母的个数(包括大小写),数字字符的个数和其它字符的个数并输出

如上

#include "stdio.h"
int main(int argc,char *argv[]){
char a,b,c,ch,i;
printf("Please enter the 10 characters...\n");
for(a=b=c=i=0;i<10;i++){
scanf(" %c",&ch);
if(ch>='a' && ch<='z' || ch>='A' && ch<='Z')
a++;
else if(ch>='0' && ch<='9')
b++;
else
c++;
}
printf("The letter: %d\nThe digit: %d\nThe other: %d\n",a,b,c);
return 0;
}

运行样例:

追问

大小写字母怎么统计

追答

题主你太忽悠人了吧?看看题是怎么说的:“统计英文字母的个数(包括大小写)”,那就是不分大小写只要是字母就累加,怎么又分别统计大、小写了?

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-12-31
#include <>

int main()
{
    int alpha,digit,others;
    char c;
    for(alpha=digit=others=0;(c=getchar())!='\n';)
    {
        if(c>='a'&&c<='z'||c>='A'&&c<='Z')
            alpha++;
        else if(c>='0'&&c<='9')
            digit++;
        else
            others++;
    }
    printf("%d %d %d\n",alpha,digit,others);
    return 0;
}

追问

大小写字母怎么统计

追答#include <stdio.h>
 
int main()
{
    int alpha,ALPHA,digit,others;
    char c;
    for(alpha=ALPHA=digit=others=0;(c=getchar())!='\n';)
    {
        if(c>='a'&&c<='z')
            alpha++;
        else if(c>='A'&&c<='Z')
            ALPHA++;
        else if(c>='0'&&c<='9')
            digit++;
        else
            others++;
    }
    printf("%d %d %d %d\n",alpha,ALPHA,digit,others);
    return 0;
}

追问

谢了

本回答被提问者采纳
第2个回答  2018-12-31
就是觉得没什么胃口大开发开博尔看到你就懂得看到你你复古风就觉得看我怎么咳嗽买啥
第3个回答  2018-12-31
吧侧妃hill空
第4个回答  2018-12-31
吧侧妃hill空

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网