//输入一行字符,统计出其中英文字母,空格,数字和其他字符的数量
#include<stdio.h>
int main()
{
char c;
int letter=0, space=0,digit=0,other=0;
while(c=getchar()!='\n')
{
if(c>='A'&&c<='Z'||c>='a'&&c<='z')
letter++;
else if(c==' ')
space++;
else if(c>=0&&c<=9)
digit++;
else
other++;
}
printf("letter=%d,space=%d,digit=%d,other=%d",letter,space,digit,other);
return 0;
}
,结果不对,实在找不出问题了

输入一行字符,统计出其中英文字母,空格,数字和其他字符的数量
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- qzjhjxj 2022-08-04 21:35关注
修改处见注释,供参考:
#include<stdio.h> int main() { char c; int letter=0, space=0,digit=0,other=0; while((c=getchar())!='\n') //while(c=getchar()!='\n') 修改 { if(c>='A'&&c<='Z'||c>='a'&&c<='z') letter++; else if(c==' ') space++; else if(c>='0' && c<='9') //if(c>=0&&c<=9) 修改 digit++; else other++; } printf("letter=%d,space=%d,digit=%d,other=%d",letter,space,digit,other); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用