#include<stdio.h>
int main()
{
int y=0,s=0,q=0,i=0;
char c[100];
gets(c);//用来接受从键盘输入的一个字符串(可带空格)
while(c[i]!='\0')
{
if((c[i]>='a'&&c[i]<='z')||(c[i]>='A'&&c[i]<='Z'))
{
y++;
}
else if(c[i]=' ')
{
s++;
}
else
{
q++;
}
i++;
}
printf("字母=%d,空格=%d,其他=%d\n",y,s,q);
return 0;
}


输入一行字符,分别统计出其中的英文字母、空格和其他字符的个数,不区分大小写。
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- 五一编程 2021-12-27 11:32关注
#include <stdio.h> #include <string.h> int main() { char c; int letter = 0, other = 0, space = 0;; printf("请输入一行字符:\n"); while ((c = getchar()) != '\n') { if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { letter++; } else if(c == ' '){ space ++; } else { other++; } } printf("字母有:%d个,空格有:%d个,其他字符有:%d个\n", letter, space, other); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用