//输入一行字符,统计出其中英文字母,空格,数字和其他字符的数量
#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无用
悬赏问题
- ¥15 关于smbclient 库的使用
- ¥15 微信小程序协议怎么写
- ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
- ¥20 怎么用dlib库的算法识别小麦病虫害
- ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
- ¥15 java写代码遇到问题,求帮助
- ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
- ¥15 有了解d3和topogram.js库的吗?有偿请教
- ¥100 任意维数的K均值聚类
- ¥15 stamps做sbas-insar,时序沉降图怎么画