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

如上
2025-04-25 06:26:22
推荐回答(4个)
回答1:

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

运行样例:

回答2:

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

回答3:

就是觉得没什么胃口大开发开博尔看到你就懂得看到你你复古风就觉得看我怎么咳嗽买啥

回答4:

吧侧妃hill空