输入一行字符,以回车符作为输入结束的标志。统计其中英文字母、数字字符和其他字符的个数

/思路:用他们的ASCII码进行判断/
#include<stdio.h>
#include<ctype.h>
int main()
{
char num;
int i ;
int count = 0;//统计数字字符的
int j = 0;//统计小写英文字母
int k = 0;//统计大写英文字母
int l = 0;//其他字符
for(i = 0; ;i ++)
{
num = getchar();
if(isdigit(num))//判断是否为数字字符
{
count ++;
}
else if(num >= 65 && num <= 90)
{
k ++;
}
else if(num >= 97 && num <= 122)
{
j ++;
}

    else
    {
        l ++;
    }
    if(num == '\n')
        break;

}
printf("letter: %d\ndigit: %d\nother: %d\n",j + k,count,l - 1);//i - 1是因为‘\n’也是其他字符

}

猜你喜欢

转载自blog.csdn.net/qq_43728862/article/details/94545227