#include <stdio.h>
int main()
{
char str[10];
int i;
int c1 ,c2, c3, c4;
for(i = 0; i < 10; i++)
{
scanf("%c", &str[i]);
if(str[i] >= 'a' && str[i] <= 'z'|| str[i] >= 'A' && str[i] <= 'Z') c1++;
else if(str[i] == ' '&& str[i] == '\n') c2 ++;
else if(str[i] >= '0' && str[i] <= '9') c3++;
else c4++;
}
printf("letter = %d, blank = %d, digit = %d, other = %d\n",c1,c2,c3,c4);
return 0;
}
统计字符个数
最新推荐文章于 2025-12-25 12:02:15 发布
该程序读取用户输入的10个字符,统计字母、空格、数字和其他字符的数量,并分别输出。对于了解基本的字符处理和条件判断有帮助。
2万+

被折叠的 条评论
为什么被折叠?



